1👍
✅
You don’t save the doctor instance anywhere.
doctor.dislikes += 1
doctor.save()
(You may also consider whether you actually need to store ‘netlikes’ in a field: it may be better to have it as a simple method on the model, which just returns self.likes - self.dislikes
.)
0👍
I would recommend that you use F() expressions for handling likes and disliked. It will increment them at the database level instead of getting an outdated value from memory. Here is the link to the official documentation on F() expressions
So the code would look something like this
doctor.dislikes = F('dislikes') + 1
doctor.save()
- [Answer]-Django ORM Confusion with Query
- [Answer]-How to get logged in user modelAdmin callable in django
- [Answer]-Django framework can't see new model online
Source:stackexchange.com