我有以下型号:
class Committee(models.Model):
customer = models.ForeignKey(Customer, related_name="committees")
name = models.CharField(max_length=255)
members = models.ManyToManyField(member, through=CommitteeMember, related_name="committees")
items = models.ManyToManyField(Item, related_name="committees", blank=True)
class CommitteeRole(models.Model):
committee = models.ForeignKey('Committee')
member = models.ForeignKey(member)
#user is the members user/user number
user = models.ForeignKey(User)
role = models.IntegerField(choices=ROLES, default=0)
class Member(models.Model):
customer = models.ForeignKey(Customer, related_name='members')
name = models.CharField(max_length=255)
class Item(models.Model):
customer = models.ForeignKey(Customer, related_name="items")
name = models.CharField(max_length=255)
class Customer(models.Model):
user = models.OneToOneField(User, related_name="customer")
name = models.CharField(max_length=255)
我需要获取属于用户通过CommitteeRole
.
像这样的东西:
committee_relations = CommitteeRole.objects.filter(user=request.user)
item_list = Item.objects.filter(committees=committee_relations__committee)
我怎样才能做到这一点?