On Sun, Jun 7, 2009 at 12:44 AM, Streamweaver<streamwea...@gmail.com> wrote:
>
> I'll have to look harder at the documentation then as I'm a bit
> confuesed.
>
> What I thought was happening was that I would get a Project object (p)
> by filtering.
>
> I thought p.release_set returned a query set of Release filtered to
> those related to that project and I could just continue to filter down
> through the custom manager.
>

>From what the documentation example says it would seem use_for_related_fields
is useful when you wany your Manager being used to provide the querysets of a
model that is the target of a relationship (Project in your case) when
accessed from a FK-defining model instance (Release),
that is, thru the forward relationship.

Your need fitering for the is in the reverse relationship (for
filtering of the FK-defining
model Release based on the related FK-targeted model Project) and that seems
to be the cause it doesn't work as you expect.

You could try something like this (a bit twisted):

class ReleaseManager(models.Manager):
   use_for_related_fields = True

   def planning_backlog(self, project=None):
       qs = self.filter(development_status__in=self.DEV_REVIEW)
       if project is None:
           return qs
       return qs.filter(project_fk=project)

   ...


class Project(models.Model):
   title = models.CharField(max_length=141)
   ...
   def planning_backlog(self):
       return Release.objects.planning_backlog(self)


class Release(models.Model):
   project_fk = models.ForeignKey(Project)
   title = models.CharField(max_length=141)

   objects = ReleaseManager()


Then you would be able to use the planning_backlog()
method of your p Project instance to get what you need.

I don't know if  use_for_related_fields is relevant/needed.

HTH

-- 
Ramiro Morales
http://rmorales.net

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to