I'm new to Django, moved from PHP with Propel ORM engine. So here is what I am currently doing in Django. My website has several models like
- Book,
- Publisher,
- Comment,
- Article and so on (it's not the point)
Each of them can can be liked or disliked by a user (only once) changing the model's rating by +1 or -1.
In terms of PHP i would create a behavior, for ex. "Rateable" which would add some fields and methods to the original model and query class (like get_rating()
, order_by_rating()
, etc) and create a separate table for each model, for ex. book_rating_history
which would hold all of the ratings for each object, to determine if the user can or can't change the rating (or show all object's ratings, if necessary). So all I would need to do is to specify the "Rateable" behavior in the model declaration, and that's all. Everything else is done automatically.
The question is - how to solve this in Django? How to model correctly? Which techniques do you use in similar cases?