What your looking for is here in the documentation: https://docs.djangoproject.com/en/1.3/topics/db/queries/#related-objects
records = models.Facility.objects.get(pk=62).schedule_set.all() On Oct 10, 8:19 pm, "Sells, Fred" <fred.se...@adventistcare.org> wrote: > I've got these two tables defined where a Facility can have multiple > schedules but a schedule can have only one facility. > > class Facility(models.Model): > id = models.CharField(max_length=2, primary_key=True) > name = models.CharField(max_length=30) > .... > > class Schedule(models.Model): > facility = models.ForeignKey(Facility) > ... > > I would like a query that returns one record for each Facility and that > record would contain at least the id (if not more) of ALL linked > schedules. So far I've only been able to return a queryset that > contains a record for each schedule at each facility. My last attempt > looked like this... > > records = models.Facility.objects.select_related().filter(id='62') > > is there a pythonic way to do this? I only need reasonable efficiency, > there's not that much data and the query is probably only run 200 times > in an 8 hour shift. -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.