I've been using something like: City.objects.filter(jobs__isnull=True)
It seems to work, but I'd really like to know if this is undesirable for any reason. On May 6, 2008, at 8:05 PM, Dmitriy Kurilov wrote: > > Hi. > > # models > > class City(models.Model): > # Fields... > > class Job(models.Model): > city = models.ForeignKey(City, related_name="jobs") > # Other fields > > > # views > City.objects.filter(jobs__pk__gt=0) > > > Is it? > > -----Original Message----- > From: Michael J <[EMAIL PROTECTED]> > To: Django users <django-users@googlegroups.com> > Date: Tue, 6 May 2008 16:29:20 -0700 (PDT) > Subject: Traversing a backward relationship > >> >> >> I hope this isn't a stupid question, so forgive me in advance. >> >> I have a Job model and a City model. Job and City are linked via a >> ForeignKey in Job. On the website, users will select a city, from a >> list of cities, and then see the corresponding jobs. >> >> Question is: how do I use the database API to only show cities that >> have jobs? >>> > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---