On Wed, Dec 16, 2009 at 12:08 PM, Jacob Kaplan-Moss <[email protected]> wrote: > On Wed, Dec 16, 2009 at 10:13 AM, Jeremy Dunck <[email protected]> wrote: >> This won't work, because deferred fields are descriptors, and >> accessing foo.field would run the query. >> >> Something you could do is foo.deferred_fields.field_name -> Boolean, >> but that seems pretty clunky to me. > > You can get at this information now if you really need to:: > > >>> e = Entry.objects.defer('body')[0] > >>> [f.attname for f in e._meta.fields if f.attname not in e.__dict__] > ['body'] >
A better approach is, IMO: >>> [f.name for f in e._meta.fields if >>> isinstance(e.__class__.__dict__.get(f.attname), DeferredAttribute)] ["body"] since it more accurately expresses what you're trying to do (also, it's crazy longer and looks way more serious). Alex > But the point is that deferred fields are an optimization. You > shouldn't need to know which fields are deferred: you should be adding > ``defer`` as a last-step optimization once you *know* the fields in > question aren't needed. > > IOW, why do I need to inspect the ``Entry`` to figure out what's > deferred? I just *told you* what's deferred in the previous line. > > Jacob > > -- > > You received this message because you are subscribed to the Google Groups > "Django developers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/django-developers?hl=en. > > > -- "I disapprove of what you say, but I will defend to the death your right to say it." -- Voltaire "The people's good is the highest law." -- Cicero "Code can always be simpler than you think, but never as simple as you want" -- Me -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
