RE: Need advice on ForeignKey query problem.

2011-10-11 Thread Sells, Fred
y need the .count() method on schedule_set() if that even makes a difference. -Original Message- From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Kevin Sent: Tuesday, October 11, 2011 8:43 AM To: Django users Subject: Re: Need advice on ForeignKey que

Re: Need advice on ForeignKey query problem.

2011-10-11 Thread Kevin
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" wrote: > I've got these two tables defined where a Facility can have mult

Need advice on ForeignKey query problem.

2011-10-10 Thread Sells, Fred
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):

Re: ForeignKey query

2010-01-29 Thread mates fila
Hi, try this: ** resultList = list( set(modelList) & set(Model1.objects.filter(model2__pk__isnull = False).distinct ()) ) ** or this: ** resultList = list( set(modelList) & set([m.model1 for m in Model2.objects.all()])

Re: ForeignKey query

2010-01-29 Thread Odd
On 29 Jan, 09:52, Odd wrote: > On 29 Jan, 09:08, Odd wrote: > > > >You originally say the model1 > > > has a foreign key to model2 - I interpret that to mean that the > > > ForeignKey is defined on model1. However, your code references > > > model1.model2_set - which would imply that the FK is de

Re: ForeignKey query

2010-01-29 Thread Odd
On 29 Jan, 09:08, Odd wrote: > >You originally say the model1 > > has a foreign key to model2 - I interpret that to mean that the > > ForeignKey is defined on model1. However, your code references > > model1.model2_set - which would imply that the FK is defined on > > model2, pointing to model1. S

Re: ForeignKey query

2010-01-29 Thread Odd
>You originally say the model1 > has a foreign key to model2 - I interpret that to mean that the > ForeignKey is defined on model1. However, your code references > model1.model2_set - which would imply that the FK is defined on > model2, pointing to model1. So, do you want the objects that are > po

Re: ForeignKey query

2010-01-28 Thread Daniel Roseman
On Jan 28, 2:33 pm, Odd wrote: > I have two models, model1 and model2, where model1 has a ForeignKey > reference to model2. > > Given a list of model1 objects, I need to determine which of these are > used as a foreign key by a model2 object, and return that list. This > is my current effort: > >

ForeignKey query

2010-01-28 Thread Odd
I have two models, model1 and model2, where model1 has a ForeignKey reference to model2. Given a list of model1 objects, I need to determine which of these are used as a foreign key by a model2 object, and return that list. This is my current effort: returnList=[] for model1 in modelList: