Friday, June 1, 2012

A question about Model.full_clean

Hi All,

Say I have this model

class TestModel(models.Model):
    my_test = models.CharField(max_length=512, blank=True)

And I try this:

In [1]: from core.base.models import TestModel

In [2]: test_model = TestModel()

In [3]: test_model.my_test = ""

In [4]: test_model.full_clean()

In [5]: test_model.save()

Ok cool, this is expected.

How about:


In [6]: test_model2 = TestModel()

In [7]: test_model2.my_test = None

In [8]: test_model2.full_clean()

In [9]: test_model2.save()

##IntegrityError raised

Is there a way for full_clean() to catch that the "my_test" field is Null when it shouldn't be, when blank=True?

If I have blank=False, it wont validate when my_test="".


Thanks

David

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment