2👍
I recommend you to change model schema. Here is suggested model:
I added UserVote
model that holds information about Question
and Choice
selected by User
.
from django.conf import settings
class UserVote(models.Model):
question = models.ForeignKey('Question')
choice = models.ForeignKey('Choice')
user = models.ForeignKey(settings.AUTH_USER_MODEL)
EDIT: How to read suggested schema: User
can have many UserVote
s (there is Many-To-One
relation – in Django you simply add ForeignKey
to UserVote
). Each UserVote
must have one-and-only one Question
and Choice
. The rest is your old schema. Btw I used Crow’s foot notation (https://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow.27s_foot_notation).
Source:stackexchange.com