我有以下型号:
class Activity(models.Model):
name = models.CharField(max_length=128)
def __unicode__(self):
return self.name
class CustomerActivity(models.Model):
customer = models.ForeignKey(Customer)
activity = models.ForeignKey(Activity)
def __unicode__(self):
return self.activity.name
我有一个过滤器可以获得客户的所有CustomerActivities:
customer_activities = CustomerActivity.objects.filter(customer=customer)
我真正需要的是基于customer_activities结果的所有Activity对象吗?
像
这样的东西 activities = Activity.objects.filter(activity_in=customer_activities)???
答案 0 :(得分:1)
试试这个
activities = Activity.objects.filter(customeractivity__customer=customer)