Hi,

There are some bugs with OR lookups in some particular conditions. See
for example:
http://groups.google.com/group/django-users/browse_thread/thread/a4679cb9a42c6ba1/1e76718aa0097628?lnk=gst&q=julien+q+malcolm+bug#1e76718aa0097628

Malcolm Tredinnick has been developping the Queryset-refactor branch
[1], which fixes that and many other hidden bugs. You should look out
because that branch should be merged to trunk soon. Also, for more
info check out Malcolm's recent interview [2].

Until then, you want to programmatically simulate the 'OR' in Python
by merging the 2 querysets.

[1] http://code.djangoproject.com/wiki/QuerysetRefactorBranch
[2] http://blog.michaeltrier.com/2008/3/3/this-week-in-django-13-2008-03-02

On Mar 7, 6:25 am, Pigletto <[EMAIL PROTECTED]> wrote:
> On 6 Mar, 00:04, Darthmahon <[EMAIL PROTECTED]> wrote:> Ahh ok. Something 
> like this then?
>
> > qset = (Q(tags__title__icontains=query) | Q(title__icontains=query))
> > results = Blog.objects.filter(qset).extra(LEFT OUTER JOIN tag ON
> > blog.tag = tag.id)
>
> No, because if you use 'tags__title__icontains' it will create SQL
> that expects tag to exist.
> Should be something like:
>
> Blog.objects.extra(tables=['APP_tags as B'],
>                            where=[''APP_blog.id is null or
> APP_blog.id=B.blog_id',
>                                       "B.title ilike '%%%s%%' or title
> ilike '%%%s%%'"],
>                            params=[query, query])
>
> I'm not sure if above will work, especially quoting % signs may be
> wrong.
>
> You should try to write working SQL first and then try to use it with
> extra. If you're using postgres you may enable logging of sql
> statements in database params and see what is executed.
>
> --
> Maciej Wisniowski
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to