我有以下 Django 模型:
class Pa(models.Model):
pa_name = models.CharField
class Pb(models.Model):
pa = models.ForeignKey(Pa, related_name="pbs")
pb_name = models.CharField()
class Pc(models.Model):
pb = models.ForeignKey(Pb, related_name="pcs")
pc_name = models.CharField()
的查询集Pc
具有以下结构:
[
{ "id": 1,
"pc_name": "pc_1",
"pb" = {
"id": 10,
"pb_name": "pb_1",
"pa" : {
"pa_name" : "pa_1" # <-- How to filter queryset by pa_name attribute?
}
}
},
{ "id": 2,
"pc_name": "pc_2",
"pb" = {
"id": 20,
"pb_name": "pb_2",
"pa" : {
"pa_name" : "pa_2"
}
}
},
# ...
]
我想返回所有那些Pcs
,在哪里pa_name
,"pa_1"
即过滤 2. 级嵌套对象。