I'm still struggling a bit with related managers. I have what I think should work right by the documentation but behavior isn't as expect.
I've pasted the actual code below but the basic deal is this. I have a Project model which has Releases so Releases have a FK field for Projects. I want to be able to get Releses with particular combinations of settings so I created a custom manager for releases. It returns the values I want just fine. My problem is with related sets of releases called from a Project. I've used the 'use_for_related_fields' flag as per the official docs but if I have a Project p and call p.release_set.in_development() for instance, it gives me all Releases in the DB with those flags instead of just the ones related to the instance in p. Any help would be appreciated. --- Start Code --- class ReleaseManager(models.Manager): # Make sure this is used for related managers. use_for_related_fields = True DEV_REVIEW = [u'P', u'W'] PLAN_REVIEW = [u'P', u'W'] # This is for releases with a development status saying it is # either in need of review 'P' or improvement 'W'. def planning_backlog(self): return super(ReleaseManager, self).get_query_set().filter (development_status__in=self.DEV_REVIEW) # This is for actionable releases that are not yet approved or rejected. def prioritization_backlog(self): return super(ReleaseManager, self).get_query_set().filter (development_status='G', point_estimate__gt=0).filter (planning_status__in=self.PLAN_REVIEW) # This is for actionable, approved releases with No velocity Points. def development_backlog(self): return super(ReleaseManager, self).get_query_set().filter (development_status='G', planning_status='A', point_estimate__gt=0, velocity_points__lt=1) # This if for actionable approved releases with veolcity points. # In Development have dev status of 'G' and planning status of 'A' # and Velocity Points > 0 def in_development(self): return super(ReleaseManager, self).get_query_set().filter (development_status='G', planning_status='A', velocity_points__gt=0) def total_velocity(self): velocity = 0 rel_set = self.in_development() for rel in rel_set: velocity += rel.velocity_points return velocity # MODELS class Project(models.Model): title = models.CharField(max_length=141) summary = models.TextField() owner = models.ForeignKey(User) documentation_site = models.URLField(verify_exists=False, null=True, blank=True) created_on = models.DateField(auto_now=False, auto_now_add=True) last_updated = models.DateField(auto_now=True, auto_now_add=True) def __unicode__(self): return self.title class Meta: ordering = ['last_updated'] class Release(models.Model): PS_CHOICES = ( (u'P', u'Pending Review'), (u'N', u'Not Adopted'), (u'W', u'Refine more'), (u'A', u'Approved for Development'), ) DEV_CHOICES = ( (u'P', u'Pending Review'), (u'N', u'Not Advisable'), (u'W', u'Needs More Detail or Work'), (u'G', u'Actionable Plan'), (u'R', u'Released') ) ESTIMATE_CHOICES = [(str(n), str(n)) for n in fib_list(13, 6)] VELOCITY_CHOICES = [(str(n), str(n)) for n in range(0, 21, 3)] project_fk = models.ForeignKey(Project) title = models.CharField(max_length=141) summary = models.TextField() owner = models.ForeignKey(User) planning_status = models.CharField(max_length=1, choices=PS_CHOICES, default=PS_CHOICES[0]) development_status = models.CharField(max_length=1, choices=DEV_CHOICES, default=DEV_CHOICES[0]) point_estimate = models.IntegerField(choices=ESTIMATE_CHOICES, default=0) velocity_points = models.IntegerField(choices=VELOCITY_CHOICES, default=0) internal_priority = models.IntegerField(default=0) created_on = models.DateField(auto_now=False, auto_now_add=True) last_updated = models.DateField(auto_now=True, auto_now_add=True) # Add my custom manager. objects = ReleaseManager() def __unicode__(self): return self.title class Meta: ordering = ["internal_priority"] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---