For statistical purposes, I need to keep a log of each time a certain instance of a Model is viewed in Django. I started off by creating a separate model, Stats, that contains a ManyToMany field to another Model that stores the date and time of the access. Every time the object is accessed in a view, I update the associated Stats object.
There are 2 problems with this approach (if not more):
- It violates the principle of not writing any data on a
GETrequest. - More importantly, it’s really slow, especially because several objects can be viewed at once. This results in a visible delay when the page is loaded.
So my question is, is there a better way of doing this? If not, what techniques are available to speed things up, such as delayed writes to the DB? I’ve never worked with that kind of thing in Django, so any advice would be appreciated.
Right, well, it seems Celery looks like a good option.