On 15 jan, 17:17, teth <godsinven...@gmail.com> wrote:
> Hello, I pickled a dictionary and stored it in my database like this:
> article.rating = article.rating + 1
> ratings[request.user.username] = 1
> article.rating_list = pickle.dumps(ratings)
> article.save()
>
> ratings looks like this:
> {'froob': 1, 'alik': 1, 'teth': 1}
>
> When I try and load the pickled string from the database it gives me
> the following error:
> KeyError at /article/testing123/up/
> '\x00'

Perhaps a bit informations would help. Like, what does the line of
code that raises looks like, and what does the field content looks
like ?

> article/testing123 loads the article testing123 from the database and
> the /up/ is to improve the rating of it. The dictionary is to prevent
> users from rating the same article twice by putting their username as
> an index in a dictionary. What am I doing wrong?

As far as I'm concerned, I'd answer that the obvious problem here is
storing a serialized dict into a db field, instead of properly using a
item/user table. But I guess this is not the answer you expect !-)

> (The pickled string
> is stored in a TEXT field)

Isn't pickle a binary format ?

Sorry, not really helpful, I'm afraid.
--~--~---------~--~----~------------~-------~--~----~
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