andro wrote: > Hello, > > ---- > class Org(models.Model): > person = models.ForeignKey(Person) > .... > > class Person(models.Model): > address = models.ForeignKey(Address) > ... > > class Address(models.Model): > street = models.CharField(max_length=50) > city = models.CharField(max_length=25) > ... > > ----- > The following does not return any results: > > Org.objects.filter(person__address__city__exact='Boston') > > Can you tell me if this is a correct filter? > Well, it certainly works, if that's what you want to know:
class Address(models.Model): street = models.CharField(max_length=50) city = models.CharField(max_length=25) def __unicode__(self): return "%s %s" % (self.street, self.city) class Admin: pass class Person(models.Model): name = models.CharField(max_length=50) address = models.ForeignKey(Address) def __unicode__(self): return self.name class Admin: pass class Org(models.Model): name = models.CharField(max_length=50) person = models.ForeignKey(Person) def __unicode__(self): return self.name class Admin: pass In [3]: Org.objects.filter(person__address__city__exact='Fairfax') Out[3]: [<Org: Python Software Foundation>] I should point out, however, that this gives you only one person per organization, which I suspect is *not* what you want. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---