2👍
You should create an ForeignKey field between the user model and the voting model. To only allow a single vote, per user; per movie, you might want to create a unique key constraint, on the voting model, over the userid and the movieid.
The vote should then contain a relation to the movie and a rating. If a user withdraws his vote you remove it from database.
Using a dictionary will lead to problems for you as you will have multiple movies.
To increase the speed and performance counting the votes you might want to take a look at caching and simply cache the number of votes and update the number every time a vote was added/withdrawn by a user on the specific movie.
0👍
You can use: update_or_create() method with django ORM.
https://docs.djangoproject.com/en/1.10/ref/models/querysets/#update-or-create
- [Answered ]-Python: zipping csv buffers
- [Answered ]-Is there a way to call a function in ListView?
- [Answered ]-Chatterbot Django and Heroku (Issues Running Example)
- [Answered ]-How to resize an image in Python without using Pillow
- [Answered ]-Pointing Django to Different Template Directory
0👍
Have you checked django-star-ratings, Star ratings for your Django models with a single template tag.
- [Answered ]-URL not resolved with APIView in Django REST Framework for non-model end point
- [Answered ]-Django1.8 and Mongoengine NameError: name 'IntegerField' is not defined
- [Answered ]-Django PostgreSQL IntegerRangeField and update_or_create