I have a Django model and I want to show some statistics about it. Like I have a field color and I want to show how many entries have their color set in "red", "green" etc.
Since I have many rows in the table and many colors I do not want to calculate the sum of each figure on each reading.
So I tried to come up with a second table containing the amount of calculation but now I have to keep this table synchronized with the original table. As soon as an entry is added, deleted, or modified, I have to update the statistics table.
How do I do something like this?
Choose Otherwise, it may be very interesting concept for this purpose to 'listen' or use your custom signal to some events like saved / deleted models. In your case, you want to listen to the An example is: django.db.models import signal import model dff items saved from ( Edit : See also for a single SQL operation count (ID) depending on your line number ... GROUP BY < / Code> is usually fast.
post_save and
post_dateep signal.
Comments
Post a Comment