Here is a fantastic Q object extension which does a LEFT OUTER JOIN.
http://www.djangosnippets.org/snippets/257/
This will solve your problems.
-Doug
On Jun 4, 4:11 am, Horst Gutmann <[EMAIL PROTECTED]> wrote:
> Hi everyone :-)
>
> I'm currently writing a small app that should store data for registered
> users and guests alike in one single model. So I made following model
> (simplied)
>
> class Content(models.Model):
> user = models.ForeignKey(User, null=True, blank=True)
>
> The problem I now face is, that Django seems not to do a LEFT OUTER JOIN
> when fetching all the instances of this model when queried with
> select_related(), which naturally results in a huge amount of queries (I
> guess on query per NOT NULL foreign key).
>
> My question now is, what options do I have to keep the query count low?
> So far I think I have following ones:
>
> (1) Query without selected related and then fill the content.user fields
> manually with a seperate WHERE IN query for the user.ids
>
> (2) Use something like Martin Fowler's NULL Object pattern and basically
> create a user with the ID 0 (or a negative integer if possible)
>
> Thank you :-)
> - Horst
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---