On 14 December 2010 09:10, marcoarreguin <marcoarreg...@gmail.com> wrote:
> Hi friends!
>
> I mean do something like this:
>
> SELECT * FROM table WHERE tags LIKE '%candy%' AND  tags LIKE '%milk%'
>
>
> I've tried:
>
> table.objects.filter(tags__icontains='candy', tags__icontains='milk')
>
> I've tried too:
>
> list = ['candy', 'milk']
> table.objects.filter(tags__icontains=list
>
> And nothing work. Help me please :s

It's usually more helpful to post errors you receive, so people
reading your message don't have to reproduce them on their own:

>>> print Table.objects.filter(tags__icontains="candy", 
>>> tags__icontains="milk").query
  File "<console>", line 1
SyntaxError: keyword argument repeated

Ok, so we can't repeat keyword arguments in Python. Thankfully, this
isn't the only way to pass query conditions to filter[1]:

>>> print Table.objects.filter(Q(tags__icontains="candy") & 
>>> Q(tags__icontains="milk")).query
SELECT "simple_table"."id", "simple_table"."tags" FROM "simple_table"
    WHERE ("simple_table"."tags" LIKE %candy% ESCAPE '\'
          AND "simple_table"."tags" LIKE %milk% ESCAPE '\' )

[1]: 
http://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects

-- 
Łukasz Rekucki

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to