views:

107

answers:

3

Suppose, I want to record say poll choices by users everyday. In this case, i have a table named vote which has columns poll , choice and user-id . So how can i out the constraint (maybe in the django models or wherever possible) that poll and user-id both should not be the same for any entry but like the same user can vote for various different polls once and obviously various users can vote for the same poll. I hope I am clear.

+2  A: 

The unique_together attribute of the Meta class of your model is what you are looking for : django docs

class Meta :
    unique_together = (('poll', 'user_id'),)
sebpiq
You'll need a comma between the two close parentheses I think `unique_together = (('poll', 'user_id'),)`.
Dominic Rodger
Oh yeah ... thanks
sebpiq
+1  A: 

unique_together may be what you are looking for.

Olivier
A: 

You want the unique_together attribute: http://www.djangoproject.com/documentation/0.96/model-api/#unique-together

scompt.com