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): > > > > 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 250k :) > > Thanks,
Alternatively you could use the normal django syntax: Country.objects.filter(soccerteam__name__isnull=False) replace 'name' with the name of a field in your SoccerTeam model - it needs to point to a specific field. Haven't timed it to see if it's faster though. -- DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---