I have 2 models: Post and Comment, each can be liked by User.
For sure, total likes should be rendered somewhere near each
PostorCommentBut also each
Usershould have a page with all liked content.
So, the most obvious way is just do it with m2m field, which seems will lead to lots of problems in some future.
And what about this?
PostandCommentmodels should have someusers_liked_ids = ArrayField(models.IntegerField())
Usermodel should also have such fields:posts_liked_ids = ArrayField(models.IntegerField()) comments_liked_ids = ArrayField(models.IntegerField())
And each time User likes something, two actions are performed:
User's id adds to Post's/Comment's
users_liked_idsfieldPost's/Comment's id adds to User's
posts_liked_ids/comments_liked_idsfield
The questions are:
Is it a good plan?
Will it be efficient to make lookups in such approach to get "Is that Post/Comment` was liked but current user
Will it be better to store likes in some separate table, rather then in liked model, but also in
ArrayFieldProbably better stay with obvious m2m?