G
G
Glory Lis2020-02-15 11:50:28
Django
Glory Lis, 2020-02-15 11:50:28

How to save a list of users who voted in a poll?

We need to have something like an array that will store the user who voted in the poll. How can this be done?

#models.py
class Profile(models.Model):
  user = models.OneToOneField(User, on_delete=models.CASCADE)
  description = models.CharField(max_length=500, default='', blank = True)
  phone = models.IntegerField(default=0, blank = True)
  image = models.ImageField(upload_to=avatar_upload_to, blank = True)

class Question(models.Model):
  question_text = models.CharField(max_length=200)
  pub_date = models.DateTimeField()

class Choice(models.Model):
  question = models.ForeignKey(Question, on_delete=models.CASCADE)
  choice_text = models.CharField(max_length=200)
  votes = models.IntegerField(default=0)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-02-15
@progneo

Options
1. Create another model where to store the survey and the user
2. In the profile, make a ManyToManyField for polls in which the user participated

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question