I have a project that looks like a simple shopping site that sells different kinds of products. For example, I have 4 models: Brand
, Product
, Consignment
. Consignment
is linked to Product
, and Product
is linked to Brand
. To reduce count of queries to databases, I want to save current state of these models(or at least some of them). I want to do it, because I show a sidebar with brands and products. So every time when user opens some page, it will execute the query to database to get those brands and products.
But when admin
add some new product or brand, I want to handle database changing and resave it. How to implement it?
Asked
Active
Viewed 38 times
0

Andrew
- 423
- 1
- 6
- 16
-
please elaborate more, you can use post_save and pre_save signal, they will hit each time some thing is changed – Rizwan Mumtaz May 07 '15 at 16:38
1 Answers
0
Your answer is by using Cache. Cache is a method to store your objects in memory/other app like redis temporarily so that you do not need send queries to database. You can read the full description here.
Or, you can use this third party library that helps you to cache Django ORM Model. Here are the example.
Brand.objects.filter(name='stackoverlow').cache()
After doing an update to the model, you need to clear
or invalidate
the cache.
invalidate_model(Brand)

Edwin Lunando
- 2,726
- 3
- 24
- 33