Re: Filtering on the existance of a "reverse" foreign key relationsship

2006-10-25 Thread Jonathan Buchanan
On 10/25/06, Christian Joergensen <[EMAIL PROTECTED]> wrote: > Daniel Roseman wrote: > >>> Country.objects.all().extra( > >>> where=['(SELECT COUNT(*) FROM appname_soccerteam WHERE > >>> appname_soccerteam.country_id = appname_country.id) > 0'] > >>> ) > >> Great idea! I did not think about th

Re: Filtering on the existance of a "reverse" foreign key relationsship

2006-10-25 Thread Christian Joergensen
[EMAIL PROTECTED] wrote: > This is already in the api, no need to write extra sql, try: > > c.soccerteam_set.count() > > http://www.djangoproject.com/documentation/db_api/#backward I know of the FOO_set-property, but I need to use it as a filter condition. As far as my Django experience goes, th

Re: Filtering on the existance of a "reverse" foreign key relationsship

2006-10-25 Thread Christian Joergensen
Daniel Roseman wrote: >>> Country.objects.all().extra( >>> where=['(SELECT COUNT(*) FROM appname_soccerteam WHERE >>> appname_soccerteam.country_id = appname_country.id) > 0'] >>> ) >> Great idea! I did not think about the 'extra' method. Works perfectly. >> Gave me a speedup factor of about 25

Re: Filtering on the existance of a "reverse" foreign key relationsship

2006-10-25 Thread Daniel Roseman
Christian Joergensen wrote: > Jonathan Buchanan wrote: > > You could use QuerySet's "extra" method to add the custom SQL > > required, which might be something like the following in this case > > (you'd need to replace "appname" with the name of the application the > > models belong to, of course)

Re: Filtering on the existance of a "reverse" foreign key relationsship

2006-10-25 Thread [EMAIL PROTECTED]
This is already in the api, no need to write extra sql, try: c.soccerteam_set.count() http://www.djangoproject.com/documentation/db_api/#backward --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" grou

Re: Filtering on the existance of a "reverse" foreign key relationsship

2006-10-24 Thread Christian Joergensen
Jonathan Buchanan wrote: >> To understand the problem, assume I have a model consisting of Country >> and SoccerTeam. >> >> The SoccerTeam has a country = models.ForeignKey(Country). >> >> Say, I need to find the countries having one or more related soccer >> teams. I was not able to come up with a

Re: Filtering on the existance of a "reverse" foreign key relationsship

2006-10-24 Thread Jonathan Buchanan
On 10/24/06, Christian Joergensen <[EMAIL PROTECTED]> wrote: > Hello > > To understand the problem, assume I have a model consisting of Country > and SoccerTeam. > > The SoccerTeam has a country = models.ForeignKey(Country). > > Say, I need to find the countries having one or more related soccer >