我的模型如下:
class AssetIdentifications(models.Model):
id = models.BigIntegerField(primary_key=True, db_index=True, editable=False, null=False)
entity = models.ForeignKey(
"Entity", db_constraint=False, null=False,
)
asset = models.ForeignKey(
"Asset", db_constraint=False, null=False
)
type = models.CharField(
max_length=32,
null=False,
)
vendor = models.CharField(
max_length=64, null=False
)
software = models.CharField(
max_length=64, null=False
)
version = models.CharField(
max_length=64, null=False
)
我想获得一个基于 的唯一值分组的查询集vendor。结果应该是这个样子:
{"vendor1": [\<list of AssetIdentifications\>], "vendor2": [\<list of AssetIdentifications\>] ...}
group_bya or函数是否可行aggregate(我在文档中没有找到类似的东西)?或者我是否必须遍历我通过过滤获得的查询集AssetIdentifications.objects.filter(entity=e)
斯蒂芬大帝
相关分类