[Django]-Where are django's annotated fields stored on the model instance?

6👍

Use this:

p.query.annotations.keys() 

It will give the list of all annotated fields.

👤Mayank

0👍

annotations are just stored as plain instance attributes (just like the values for the ORM fields FWIW). You can use dir(my_model_instance) to see all the attributes (class and instance ones) names, or my_model_instance.__dict__.keys() for the plain instance attributes only.

Leave a comment