I have 2 models: Post
and Comment
, each can be liked by User
.
For sure, total likes should be rendered somewhere near each
Post
orComment
But also each
User
should 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?
Post
andComment
models should have someusers_liked_ids = ArrayField(models.IntegerField())
User
model 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_ids
fieldPost's/Comment's id adds to User's
posts_liked_ids/comments_liked_ids
field
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
ArrayField
Probably better stay with obvious m2m?