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 if you did not catch that already try:
Offer.objects.filter(Q(searchterms__term__exact = 'ThemePark') & Q(searchterms__term__exact = 'London')) , although if it is returning an empty query set and not failing, you probably did catch my error. If this does not work, have you tried instantiating the Terms objects and passing them to the query, (obviously not an efficient way of doing this but may provide some insight into whether or not the m2m query works), i.e. t1 = Terms.objects.get(term__exact = 'ThemePark') t2 = Terms.objects.get(term__exact = 'London') Offer.objects.filter(Q(searchterms = t1) & Q(searchterms = t2)) -richard On 9/17/07, merric <[EMAIL PROTECTED]> wrote: > > > 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 = '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 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): > > > return self.search_term > > > > > class Offer(models.Model): > > > searchterms=models.ManyToManyField(Terms,blank=True) > > > > > On Sep 17, 1:52 am, r_f_d <[EMAIL PROTECTED]> wrote: > > > > 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 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 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, Merric Mercer <[EMAIL PROTECTED]> > wrote: > > > > > > > > > I have a model "OFFER" that has has many to many relationship > with > > > a > > > > > > > model "TERMS". > > > > > > > > > Class OFFER: > > > > > > > terms=models.ManyToMany(Terms) > > > > > > > > > Assuming I have the following value for 3 records in Term > > > > > > > term1=2 > > > > > > > term2=5 > > > > > > > term3=8 > > > > > > > > > I want to return ONLY those offers which have ALL three of > these > > > terms . > > > > > > > I've tried: > > > > > > > > > qs=Offer.objects.all > > > ().filter(terms=term1).filter(terms=term2).filter(terms=term3) > > > > > > > but this doesn't work - I always end up with an empty query > set. > > > > > > > > > What am I missing? > > > > > > > > > Cheers > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---