On Wed, May 27, 2009 at 5:17 AM, Daniel Watkins <[email protected] > wrote:
> > Hello all, > > I'm seeing the following behaviour: > In [2]: Project.objects.all() > Out[2]: [<Project: Debian (Distributions)>, <Project: Test (Space Test)>, > <Project: Test2 (Groupware)>, <Project: aBC (Distributions)>, > <Project: asdun (Groupware)>, <Project: eR (Distributions)>] > > In [3]: Project.objects.filter(trainingprogramme__isnull=False) > Out[3]: [<Project: Debian (Distributions)>, <Project: Debian > (Distributions)>] > > In [18]: [p for p in Project.objects.all() if > list(p.trainingprogramme_set.all()) != []] > Out[18]: [<Project: Debian (Distributions)>] > > The middle of those 3 should only return [<Project: Debian > (Distributions)>]. Anyone know what's going on here? > > > Cheers, > > Dan > > > > > Because of the way SQL works when filtering on a many to many / or reverse foreign key in certain ways you can get duplicates, you can use distinct(); http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct to remove these. Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---

