In model.py:
#1 class B1(models.Model): u1= models.CharField(max_length=32) #多 class B2(models.Model): f1 = models.CharField(max_length=32) f2= models.IntegerField() f3 = models.ForeignKey('B1')
In views.py:
# The foreign key f3 in B2 points to a list of all objects with u1='x' in B1 obj_list = B2.objects.filter(f3__u1= ' x ' ) # The foreign key f3 in B2 points to the list of values of f1 of all objects with u1='x' in B1 obj_f1_list = B2.objects.filter(f3__u1= ' x ' ).values_list( ' f1 ' )