On Apr 30, 2008, at 2:33 PM, Ken Arnold wrote:
>
> What would you all think about a Meta attribute for models for
> select_related, analogous to ordering? i.e., default to selecting
> these related fields for any query on this model.
>
> For example, I have a model roughly like:
>
> class Contribution(models.Model):
> # content...
> creator = models.ForeignKey(User)
>
> Nearly every time I want to display a contribution, I'm going to want
> the username. It would be nice if, instead of sprinkling
> `select_related('creator__username')` all over the code (thanks for
> that very nice addition though, Malcolm), I could just declare on the
> model something like:
>
> class Meta:
> related = ('creator__username',)
>
> Canceling could be done like `select_related('-creator__username')`
> perhaps.
>
> What do people think?
Without assigning my own preference to this solution, I would say that
canceling might better be done as a non-generative option, as there's
a previous discussion on this topic:
http://groups.google.com/group/django-developers/browse_thread/thread/fb195cbcda2e4b44/f85fb54382a7847a?#f85fb54382a7847a
gav
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---