If I understand what you're doing here, you need to be very careful.  
Converting a dictionary to a string (or pickle) does not guarantee that 
two equal dictionaries convert into two equal strings (or pickles), 
especially if your version of Python changes.  For example, your code 
below may create a pickle with the key 'foo' first, or it may create a 
pickle with the key 'bar' first.  Both pickles un-pickle to an 
equivalent dictionary, but the pickles won't compare as equal, and your 
queries will fail.

I could be wrong, and the pickle module provides some guarantee about 
the equivalency of pickles, but I don't think so.

--Ned.
http://nedbatchelder.com/blog

[EMAIL PROTECTED] wrote:
> I fixed this -- not Django's fault at all. For the full field code, go
> to http://www.djangosnippets.org/snippets/513/
>
> On Dec 13, 8:08 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>   
>> Hey All,
>>
>> I've just written a custom model field for storing anything which is
>> pickle-able (generally this will be used for storing dictionaries). It
>> all works great, apart from when I want to perform a query on objects
>> using the field as an argument. When doing something like:
>>
>> SomeModel.objects.filter(my_field={'foo': 'bar', 'bar': 'baz'})
>>
>> However, it seems to reduce my dictionary to an iterable containing
>> just the dictionary keys (so, in this case ['foo', 'bar']). I presume
>> Django is doing this by iterating over the dictionary, but obviously
>> this doesn't work for my field. Is there any way to stop Django from
>> doing this, away from overriding query methods in the manager to
>> convert the dictionary to something non-iterable?
>>
>> Any help much appreciated!
>>
>> Thanks,
>> O
>>     
> >
>
>   

-- 
Ned Batchelder, http://nedbatchelder.com


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to