我有下面的查询结果集,它获取了一个到多个层次结构数据,但由于某种原因,结果集json列表没有父字段(pid,loc)
以下是查看代码
res=Can.objects.select_related().all().prefetch_related('ppid__loc')
以下是模型:
class Cate(models.Model):
pid=models.IntegerField(unique=True, db_column='pid', primary_key=True)
loc=models.CharField(max_length=100)
class Meta:
managed="false"
db_table="prf"
class Can(models.Model):
ppid=models.ForeignKey(to=Cate, db_column='ppid')
sid=models.IntegerField()
sname=models.CharField(max_length=100)
class Meta:
managed="false"
db_table="sf"
当我应用断点时,我可以看到所有字段,但结果集如下所示:
[{"sid":1,"sname":"housing",ppid:1},{..},{..}]
我期待的是:
[{"pid":2,"loc":"Bangalore","skills":[{"sid":1,"sname":"housing","ppid":1},{..},{..}]},{"pid":3,"loc":"New York","skills":[{{"sid":1,"sname":"housing","ppid":9},{..}]}]
我错过了什么?