django orm cross-table query nonsense least minimal version

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 ' )

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324689008&siteId=291194637