I am trying to serialize a queryset into json using my custom iterator. On the models I detect the fields in the model and insert them into the JSON dict as I need them.
I am having trouble figuring out how to determine which fields have been deferred in the model using the defer or only queryset function.
Is there a way, and how, to find out which fields are deferred and how to skip over them?
Current version of Django (1.9) has a method on all model instances:
instance.get_deferred_fields()
This seems to be the "official" implementation of Alexey's answer.
Somewhat buried...
queryset.query.get_loaded_field_names()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With