How to set up brine for django model objects

My application uses a per-user session to allow multiple sessions from the same user to share state. It works very much like a django session by etching objects.

I need to decompose a complex object that references django model objects. A standard etching process stores a denormalized object in brine. Therefore, if an object changes in the database between etching and unpacking, the model is now out of date. (I know that this is also true for objects with memory, but etching is a convenient time to solve it.)

Obviously, it would be cleaner to store this complex in a database, but this is not practical. The code for it necessarily changes rapidly as the project develops. The need to update the database schema every time when changes to the object's data model slow down the project.

So I would like not to sort the complete django model object. Instead, just save your class and id and reload the contents from the database at boot time. Can I specify my own brine method for this class? I am happy to write a wrapper class around the django model to handle lazy selection from db if there is a way to do etching.

+4
source share
2 answers

It is not clear what your goal is.

"But if I just store the identifier and class in the tuple, then I will definitely return to the database every time I use any django objects. I would like to be able to store those using in memory during the page request."

This doesn't make sense since the view function is - and you have local variables in your view function that keep your objects in place until you finish.

In addition, Django ORM uses a cache.

Finally, the session provided by Django is the usual place for โ€œobjects in memoryโ€ between requests.

You do not need to calculate anything.

+1
source

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

0
source

Source: https://habr.com/ru/post/1304158/


All Articles