我这样做:
p = MyModel.objects.filter(user__username="me").annotate(friend_count=Count(friends))
当我看着:
p[0]._meta.get_all_field_names()
它返回模型上定义的所有内容,但不返回带注释的字段“friend_count”
是否有一个函数可以用来查看特定模型实例的所有注释字段?
最佳答案
使用这个:
p.query.annotations.keys()
它将给出所有注释字段的列表。
关于django - django 的注释字段存储在模型实例的哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11333197/