Force CharField's Choices

Viewed 644

I have few models.CharField objects in my Model, with the choices attribute.

This is working great as far as the GUI is concerned, But I want to block values other than these specified in the choices attribute in the code itself (to protect myself from bugs).

Is there a way to raise an exception (I believe it'll be a ValueError) when trying to save a string which is not in the choices list?

2 Answers
Related