0

我有以下对象结构:

class Customer(models.Model):
    name = models.CharField('Customer Name', max_length=64)

class Location(models.Model):
    customer = models.ForeignKey(Customer)
    groups = models.ManyToManyField(Group, blank=True, null=True)

class Group(models.Model):
    name = models.CharField('Group Name', max_length=64)

如何找到客户的所有唯一组对象?

4

1 回答 1

2

对于一个customer对象,

groups = Group.objects.filter(location__customer = customer).distinct()

关于跨关系查找的文档

于 2013-08-20T18:52:37.137 回答