On Fri, Mar 5, 2010 at 3:56 AM, aditya <bluemangrou...@gmail.com> wrote:
> I would like to add a new filter for models to my django build that
> can be used as follows:
>
> tags = ['tag1','tag2','tag3'....'tagn']
> i = Image.objects.filter(tags__contains_any=tags)
>
>
> Essentially, instead of passing a string, I pass a list and get a set
> of valid objects that match *any* of the items in the list. I'm a loss
> for where to look for the relevant code, though....I'm trying to find
> where the 'contains' filter has been implemented, so that I can take a
> look at how its written. Currently I'm looking at db.models.query and
> db.models.query_utils.  Where should I be looking?
>
> Thanks for any help you all can provide!

There are two issues in here.

Firstly, there is the question of whether __in will solve your
problem. If it does, you don't need a custom filter clause, so your
life gets a whole lot easier :-)

Second is the issue of whether you can add your own filter clauses to
queries. The short answer is that it is possible (GeoDjango, for
example, adds a bunch of extra query clauses), but it's not easy, and
it's not a documented approach. Making custom filter clauses easier to
add has been proposed in the past, we just haven't gotten around to
adding them.

Yours,
Russ Magee %-)

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

Reply via email to