Pickling Django QuerySet
Question: 
    from myapp.models import MyModel
    from cPickle import *
    
    tmp = MyModel.objects.all()[:1]
    print(loads(dumps(t, -1)) == t)
    #Output is "False"
    

In my case pickled query result differs from unpickled. I already read here:
<https://docs.djangoproject.com/en/dev/ref/models/querysets/#pickling-
querysets> that such operations are actually allowed. So - what am I doing
wrong?

upd #1: Tried cPickle and regular Pickle - got 'False' from both  

upd #2: Possible resolution - converting QuerySet to Python list with
`list()`. Found it while reading these:
<https://docs.djangoproject.com/en/dev/ref/models/querysets/#when-querysets-
are-evaluated>


Answer: The problem is that you are trying to compare two querysets and querysets
doesn't have a `__cmp__` method defined.

So, you can compare a queryset with itself and you will get this:

    
    
    >> tmp == tmp
    True
    

This is because, as there are no `__cmp__` method, `==` evaluates `True` if
both objects have the same identity (the same memory address). You can read it
from [here](http://docs.python.org/2/reference/datamodel.html#object.__cmp__)

So, when you do this:

    
    
    >> loads(dumps(tmp, -1)) == tmp
    False
    

you will get a `False` as a result because objects have different memory
addresses. If you convert queries into a "comparable" object, you can get the
behaviour you want. Try with this:

    
    
    >> set(loads(dumps(tmp, -1))) == set(tmp)
    True
    

Hope it helps!

