I’m making an app using django where users can make posts. To add likes and views which can be counted and sent to be displayed on frontend i’m thinking of two approaches.
-
is to use a reverse foreign-key relation between post’s model and likes model to dynamically count the instances of the likes model each each time. So create/delete instances of like model to represent like/unlike
-
is to use a integer field model to store the counts in the database.
-
use many-to-many field where number if likes for a post is determined my NO. Of user instances associated with post.likes
Which approach does instagram use? Which approach would be the ultimate choice? Considering keeping costs low while maintaining scalability possibilities. Thanks