Ah, I somehow missed distinct() when reading the docs. Sorry, and
thanks for your help.


On Jun 7, 2:20 pm, Karen Tracey <kmtra...@gmail.com> wrote:
> On Sun, Jun 7, 2009 at 8:47 AM, James <ja...@jarofgreen.co.uk> wrote:
>
> > So the models I am using are at
>
> >http://github.com/jarofgreen/TaggedWiki/blob/e45ede936ebc2e88c9b60de7...
>
> > Here is some test code to run on an empty DB:
>
> > >>> from taggedwiki.models import *
> > >>> s = Space.objects.create(Title='test')
> > >>> p1 = Page.objects.create(Title='blah', Body='',
> > Space=s,LastUpdateIP='127.0.0.1')
> > >>> p2 = Page.objects.create(Title='blah2', Body='',
> > Space=s,LastUpdateIP='127.0.0.1')
> > >>> p2.addTag('blah')
> > >>> Tag.objects.all()
> > [<Tag: blah>, <Tag: blah2>]
> > >>> Tag.objects.filter(page__Space=s)
> > [<Tag: blah>, <Tag: blah>, <Tag: blah2>]
>
> > Why is tag 'blah' repeated twice in that last query? I assumed that
> > the results from a query set would be unique - am I wrong? Are there
> > any other instances where you don't get unique objects?
>
> Tag 'blah' is associated with Space s twice, once via p1 (auto-added in your
> Page save()) and once via the p2 addTag call you show.  By default such
> duplicates are not removed from QuerySet results, if you want them to be you
> need to use specify distinct():
>
> http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to