Hi, I am new to Django and Python and have been working through the tutorial. I would like to modify the polls app in the tutorial such that I can track individual users who vote in a poll, keep a record of their choice, and not allow any user to vote more than once in any given poll. Briefly, there are many polls, each poll being linked to several choices. Each user can vote in many polls, but is allowed to vote only once in each individual poll. Whats the best way to enforce this? I tried to enforce this by using the unique_together feature to bind a specific user, poll, choice combination together (within the Choice class). It didnt work. Here is the code I tried:
from django.db import models import datetime class User(models.Model): name = models.CharField(max_length=100) email = models.EmailField() def __unicode__(self): return self.name class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def __unicode__(self): return self.question class Choice(models.Model): poll = models.ForeignKey(Poll) user = models.ManyToManyField(User) choice = models.CharField(max_length=200) votes = models.IntegerField() def __unicode__(self): return self.choice class Meta: unique_together = ("poll", "user", "choice") My error message: Error: One or more models did not validate: polls.choice: "unique_together" refers to user. ManyToManyFields are not supported in unique_together. polls.choice: "unique_together" refers to user. This is not in the same model as the unique_together statement. I would appreciate any suggestions/corrections, Thanks, Meenakshi -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.