Last active
August 29, 2015 14:08
-
-
Save kezabelle/bab4426a8d6746303f85 to your computer and use it in GitHub Desktop.
getting everything but deferred attributes for a given Django model. Because otherwise, doing getattr() forces evaluation of deferred fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see https://github.com/django/django/blob/c32bc1a7a7bbb3d5bd0a2c11bc77dd5ab1c32fbc/django/db/models/base.py#L415 | |
# and http://stackoverflow.com/questions/4523651/how-to-tell-which-fields-have-been-deferred-onlyd-in-a-django-queryset | |
concrete_fieldnames = (x.attname for x in obj._meta.concrete_fields) | |
non_deferred = dict( | |
(attr, getattr(obj, attr)) | |
for attr in concrete_fieldnames | |
if not isinstance(obj.__class__.__dict__.get(attr), DeferredAttribute) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment