[Django]-What is the point of specifying Integer Choices in django models?

4👍

The point of providing choices is for user provided data validation. Your forms won’t accept any other input that the choices you defined.

As a developper, you are free to put any data you want, as long at it complies with the database constraints you defined.

You need to note that in the provided example, you did not validate your model before saving it. If you did so, it would have triggered an exception.

c = Card()
c.suit = 5
# Validation !
c.full_clean()
c.save()

Leave a comment