Friday, September 2, 2011

Pickling a QuerySet

An interesting question here, not sure if anybody has tried to pickle
their QuerySets before.

Here's an example that does work:
entry_list = Entry.objects.all()
response =
HttpResponse(pickle.dumps(entry_list),mimetype='application/x-
pickle.python')
response['Content-Disposition'] = 'attachment; filename=kbase.dat'
return response

This is one of my views. Now, I have another view that takes a file
upload to take in this pickled data. My objective is to be-able to
export an entire model, or select items in a model.

It seems to unpickle just fine in the same site, and all the entry
objects in the queryset seem to be intact. Now, what if, the target
site did not have the same entry objects and this pickle was imported
in? The model is the exact same, just the actual data in the database
is different. Is there an easy way to compare for differences and
sync the pickled data with the data in the database? I won't run into
any conflicts as data is never removed on either end, data is just
merely added on one site, and I want to manually sync it with a
different site.

I'll be running a few tests to see what happens with this data and
post back here to let anybody who wants to know, know.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment