Monday, May 30, 2016

Re: Choice fields not validated while saving to database

Django doesn't validate models automatically. You can validate model manually as per docs: 
<https://docs.djangoproject.com/en/1.9/ref/models/instances/#validating-objects>

On 30.05.2016 12:38, Vinayak Kaniyarakkal wrote:
The following code is "failing silently"
 
class MyModel(models.Model):
    CHOICES = ((0, 'Inactive'), (1, 'Active'),)
    my_field = models.PositiveIntegerField(choices=ACTIVE_CHOICES, default=2)

obj = MyModel.objects.all()[0]
obj.my_field=100
obj.save()

Should I raise a bug in Django?
 
--
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+unsubscribe@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/a073eaca-0e92-4685-ae93-113fc8f0840e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment