[Django]-How to customize pickle for django model objects

1đź‘Ť

âś…

It’s unclear what your goal is.

“But if I just store the id and class in a tuple then I’m necessarily going back to the database every time I use any of the django objects. I’d like to be able to keep the ones I’m using in memory over the course of a page request.”

This doesn’t make sense, since a view function is a page request and you have local variables in your view function that keep your objects around until you’re finished.

Further, Django’s ORM bas a cache.

Finally, the Django-supplied session is the usual place for “in-memory objects” between requests.

You shouldn’t need to pickle anything.

👤S.Lott

0đź‘Ť

You can overload the serialization methods. But it would be simpler to put the id and class in a tuple or dict and pickle that.

👤mikerobi

Leave a comment