Eric/r.tirrell, That worked like a charm. Thanks a bunch!
However, I did have to add distinct() at the very end of the call, otherwise, I was getting back as many duplicates of a City as there were Jobs in that city. Any reason why? On May 7, 9:10 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > As far as I know, that's fine. Michael J. could use > City.objects.exclude(jobs_isnull=True) to accomplish what he seemed to > be going for. > > On May 7, 2:09 am, Eric Abrahamsen <[EMAIL PROTECTED]> wrote: > > > 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 -~----------~----~----~----~------~----~------~--~---