+14

How do i correct this ?

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

11/15/2019 9:29:14 AM

Mirielle🐶 [Inactive]

9 Answers

New Answer

+7

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 UPDATE likes SET count = count + 1 WHERE post_id =...

+10

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 ": increment elif users-id == post.like.id ": increment else: increment increment is a newly created and not directly from the db

+5

Ok. Glad you got sorted. It's an area of interest for me at the moment. PHP and SQL. Just figured out the other week how to update user logins with timestamps. So, I'm learning as I go.

+4

Something you might find useful in the future. It's about timestamps, even down to microseconds. https://stackoverflow.com/questions/14461851/how-to-have-an-automatic-timestamp-in-sqlite

+4

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

+3

Are you recording a timestamp with each recorded click? Do you have entropy or a unique identifier to distinguish the clicks?

+1

Use transactions

-3

what is sql

-4

hay what are you dowing