Check if Django model field choices exists

Posted by Justin Lucas on Stack Overflow See other posts from Stack Overflow or by Justin Lucas
Published on 2010-03-26T01:22:33Z Indexed on 2010/03/26 3:13 UTC
Read the original article Hit count: 330

Filed under:
|
|

I'm attempting to check if a value exists in the choices tuple set for a model field.

For example lets say I have a Model like this:

class Vote(models.Model):

VOTE_TYPE = ( (1, "Up"), (-1, "Down"), )

value = models.SmallIntegerField(max_length=1, choices=VOTE_TYPES)

Now lets say in a view I have a variable new_value = 'Up' that I would like to use as the value field in a new Vote. How can I first check to see if the value of that variable exists in the VOTE_TYPE tuple? Thank you.

© Stack Overflow or respective owner

Related posts about python

Related posts about django