Hello all,
I have the following code:
class GroupDepartmentManager(models.Manager):
def get_query_set(self):
return super(GroupDepartmentManager, self).get_query_set().filter(group='1')
class Department(models.Model):
name = models.CharField(max_length=128)
group = models.ForeignKey(Group)
def __str__(self):
return self.name
objects = GroupDepartmentManager()
... and it works fine. Only thing is that I need to replace group='1' with group=(the group specified by group = models.ForeignKey(Group)). I am having quite a time trying to determine whether that foreign key needs to be passed into the class, or into the get_query_set function, or what. I know that you can accomplish this with group.department_set.filter(group=desired group), but I am writing this model for the admin site, so I need to use a variable and not a constant after the = sign.
Thanks in advance for any advice you all can provide.