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 -~----------~----~----~----~------~----~------~--~---