The choices don't enforce any default validation. But if you are populating
the data from a http call then use ModelForm they show the invalid_choice
error message on entering value other than defined choices

On Mon, Mar 21, 2016 at 1:59 PM, Amine Yaiche <yaiche.a...@gmail.com> wrote:

> Hi everyone,
>
> Given a field in a model that uses choices:
>
> CHOICES = (
>     (0, "choice_0"),
>     (1, "choice_1")
> )
>
> foo = models.IntegerField(choices=CHOICES)
>
>
> If i put a value other than 0 or 1, django will accept it. Is that
> possible that we instruct Django to accept only values that are mentioned
> in CHOICES without creating a validator function.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/78d84aa0-506f-4d5c-9590-ef6325c255e0%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/78d84aa0-506f-4d5c-9590-ef6325c255e0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMi_2%3DETuiuo%3D0xcz%3D3haWv5ayXpurpMazZP1rUsdEcLYxJ%3DJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to