I created a database that allows other users to like and comment on posts.
The "like" button and "commnet" button are different tables respectively with both having a ForeignKey relationship to the Posts.
Everything is working fine is multiple users liked a post at different time, but if multiple users clicked the 'like" button at the same time, it'll be counted as 1.
Is something wrong with the foreignkey relationship that exist between likes and post or something?
I'm using SQLite and Python( not django ) in the backend
Sounds like some sort of synchronization issue.
When you update the number of likes, how do you determine the new value? Is it based on the number of current likes that the user is seeing?
I think it should work if the increment is done directly in the sql update statement, like so
SET count = count + 1
WHERE post_id =...
Thanks, i figured out where the bug is ..
I'm using an "if-elif" statement then forgot to add a new condition to the else statement.
So i'm using
"if users-id == post.like.id ":
elif users-id == post.like.id ":
increment is a newly created and not directly from the db
Xyenia 🦉 , there's an sql table called "User"..then whenever i imported that to python, it counts as one but xd that isn't the problem as i'm able to filter from there. The conditional statement is wrong