我有3个tables:-
class Profile(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField()
.....
#some more field
.....
class ProfileTestMapping(models.Model):
id = models.AutoField(primary_key=True)
profile = models.ForeignKey(Profile)
test = models.ForeignKey(Test)
.....
#some more field
....
class Test(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField()
.....
#some more field
....
1.有很多测试。所以我想得到如下数据this:-
This is a raw array I am writing for the example purpose.
profileList = [
{
profileName: 'any-name',
......
otherProfileDetails
.......
testList: [
{
name: testName,
id: 463743
},
{
name: testName2,
id: 463743
}
]
}
]
我得到了 count
与使用 annotate
但是没有得到测试的细节,这些细节被Map到概要文件中。
updated:- current 查询我得到的是计数的数目,而不是Map测试的列表data:-
Profile.objects.filter(isDisable=0).value('id', 'name').annotate(
testCount = Count('profiletestmapping__test_id')
testList = //Unable to get list of related data
)
1条答案
按热度按时间0mkxixxg1#
在选择配置文件时,可以使用预回迁相关来加入所有测试。