Not sure if this is efficient, but you can try wrapping the values_list in
a set() call.

>>> set(ids1) == set(ids2)

True

>>> set(ids1) & set(ids2)

set([1])

>>> ids3 = set([])

>>> r = set(ids1) & set(ids3)

>>> r

set([])

>>> len(r)

0


Cheers,
AT

On Thu, Apr 5, 2012 at 6:07 AM, Thomas Guettler <[email protected]> wrote:

> I was surprised, that comparing querysets does not work:
>
> {{{
> from django.contrib.auth.models import User
> user_id=User.objects.all().**order_by('id')[0].id
>
> if not User.objects.filter(id=user_**id)==User.objects.filter(id=**
> user_id):
>    print 'Not equal? I think they should be'
>
> ids1=User.objects.filter(id=**user_id).values_list('id', flat=True)
> ids2=User.objects.filter(id=**user_id).values_list('id', flat=True)
> if not ids1==ids2:
>    print 'Not equal? I think they should be: %s %s' % (ids1, ids2)
>
> }}}
>
> Both, django 1.3 and 1.4 print this result:
>  Not equal? I think they should be
>  Not equal? I think they should be: [1] [1]
>
> I could not find a documentation of this in the django docs[1].
>
> Before creating a doc-ticket I want to ask here.
>
> [1] 
> https://docs.djangoproject.**com/en/dev/ref/models/**querysets/<https://docs.djangoproject.com/en/dev/ref/models/querysets/>
>
> --
> Thomas Guettler, http://www.thomas-guettler.de/
> E-Mail: guettli (*) thomas-guettler + de
>
> --
> 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 django-users+unsubscribe@**
> googlegroups.com <django-users%[email protected]>.
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
> .
>
>

-- 
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.

Reply via email to