issue with many to many field

9 views
Skip to first unread message

jul

unread,
Jan 4, 2010, 11:44:22 AM1/4/10
to Djapian Users
hi,

I tried to filter a resultset by a many to many field and failed. Can
it be done? What I tried is shown below. What's wrong?
Thank you
jul


To show that a Restaurant instance named "bella napoli" exists, and
that it has two categories:

In [41]: Restaurant.objects.get(name="bella napoli").category.all()
Out[41]: [<Category: french>, <Category: italian>]


The following works:

In [50]: Restaurant.indexer.search('bella').filter(name="bella napoli")
[0].instance
Out[50]: <Restaurant: bella napoli>

But this does not:

In [54]: category=Category.objects.get(name="italian")
In [55]: Restaurant.indexer.search('chez').filter(category=category)
[0].instance
---------------------------------------------------------------------------
(...)
IndexError: list index out of range

Alex Koshelev

unread,
Jan 17, 2010, 8:36:53 PM1/17/10
to djapia...@googlegroups.com
Hi, jul!

It is hard to answer to your question without indexer definition is present but I'll try.

First of all only fields defined as tags can be filtered. M2M fields are indexed by its objects __unicode__ values joined with commas. So if you want to search against this fields you have to use `__contains` lookup and unicode value of specific object. For you case:

Restaurant.indexer.search('chez').filter(category__contains=unicode(category))

Hope this helps.
---
Alex Koshelev





--

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



Reply all
Reply to author
Forward
0 new messages