Re: Using a filter with many to many relationship

2008-02-10 Thread ecir hana
On Feb 11, 2008 12:02 AM, Tim Chase <[EMAIL PROTECTED]> wrote: > >>offers = Offer.objects.all() > >>for term in ('ThemePark', 'London'): > >> offers = offers.extra(where=[""" > >>EXISTS ( > >> SELECT 0 > >> FROM app_offer_term ot > >>ON o.id = ot.

Re: Using a filter with many to many relationship

2008-02-10 Thread Tim Chase
>>offers = Offer.objects.all() >>for term in ('ThemePark', 'London'): >> offers = offers.extra(where=[""" >>EXISTS ( >> SELECT 0 >> FROM app_offer_term ot >>ON o.id = ot.offer_id >>INNER JOIN app_term t >>ON ot.term_id = t.

Re: Using a filter with many to many relationship

2007-09-17 Thread Tim Chase
>> Ok, the query should then be: >> >> Offer.objects.filter(Q(terms__term__exact = 'ThemePark') & >> Q(terms__term__exact = 'London')) > > Still returns an empty query set. Checking some of the other posts I > think this is a failing which is particular to ManyToMany > relationships the probl

Re: Using a filter with many to many relationship

2007-09-17 Thread Richard Dahl
What version of django are you using? I am using the latest from svn and this does work for me, however I just looked at your model definitions again and realized that the query I sent you would not work. I didn't notice that in your Offer model the related name is 'searchterms', not 'terms', so

Re: Using a filter with many to many relationship

2007-09-17 Thread peschler
Wouldn't the following code solve the problem without Q objects? Offer.objects.filter(searchterms__term='ThemePark', searchterms__term='London') According to the docs the filter parameters are AND'ed. Admittedly I never used this in combination with ManyToMany fields, so I might be wrong here.

Re: Using a filter with many to many relationship

2007-09-17 Thread merric
Still returns an empty query set. Checking some of the other posts I think this is a failing which is particular to ManyToMany relationships On Sep 17, 4:33 pm, "Richard Dahl" <[EMAIL PROTECTED]> wrote: > Ok, the query should then be: > > Offer.objects.filter(Q(terms__term__exact = 'ThemePar

Re: Using a filter with many to many relationship

2007-09-17 Thread Richard Dahl
Ok, the query should then be: Offer.objects.filter(Q(terms__term__exact = 'ThemePark') & Q(terms__term__exact = 'London')) -richard On 9/17/07, merric <[EMAIL PROTECTED]> wrote: > > > I only want records that have both the terms, "ThemePark" AND "London" > > The attribute of Terms that contain

Re: Using a filter with many to many relationship

2007-09-17 Thread merric
I only want records that have both the terms, "ThemePark" AND "London" The attribute of Terms that contains 'ThemePark' and 'London is simply 'term' The full model is: class Terms(models.Model): term=models.CharField(maxlength=100,core=True,help_text="search term") def __unicode__(self)

Re: Using a filter with many to many relationship

2007-09-16 Thread r_f_d
Couple of things so I understand better, What is the attribute of term that contains 'ThemePark' and 'London' ? What are you trying to end up with, all records with themePark or only records with themepark and London ? -richard On Sep 16, 11:36 am, merric <[EMAIL PROTECTED]> wrote: > I can't get

Re: Using a filter with many to many relationship

2007-09-16 Thread merric
I can't get this to work for me. For example, I have two records which both share the term 'ThemePark", one of these records also has the additional term "London". However, when I run your suggestion I get an empty query set. Cheers On Sep 15, 2:27 am, r_f_d <[EMAIL PROTECTED]> wrote: > You ar

Re: Using a filter with many to many relationship

2007-09-14 Thread r_f_d
You are missing Q. try from django.db.models import Q (I think that is where it resides but cannot verify right now, a quick check of the documentation should confirm) Offer.objects.filter(Q(terms__exact = 'term1') & Q(terms__exact = 'term2') & Q(terms__exact = 'term3)) On Sep 14, 6:46 pm, Me