django 的注释字段存储在模型实例中的什么位置?

9-b*_*its 3 django django-models django-aggregation

我正在这样做:

p = MyModel.objects.filter(user__username="me").annotate(friend_count=Count(friends))
Run Code Online (Sandbox Code Playgroud)

当我看:

p[0]._meta.get_all_field_names()
Run Code Online (Sandbox Code Playgroud)

它返回模型上定义的所有内容,但不返回带注释的字段“friend_count”

是否有一个函数可以用来查看特定模型实例的所有带注释的字段?

小智 5

用这个:

p.query.annotations.keys() 
Run Code Online (Sandbox Code Playgroud)

它将给出所有带注释的字段的列表。