Open mrTable opened 10 years ago
null
behaviour was merged in #734 , does it works for you?
This behaviour looks odd comparing to django's.
Currently the required
attribute is pretty much the same as the blank
attribute of django's field.
But the null
attribute in django is a constraint to the database, whereas in mongoengine it's just a flag to whether use the default value or None.
In my opinion it should work exactly as the validation in django
This would also become an issue in StringField, when the user wants it to be required, but also wants to allow it to be an empty string.
Django model fields have two attributes "blank" and "null" that can be used for empty value validation, when mongoengine document field has only "required" attribute. Since mongoengine intends to have minimum amount of differences with django orm, it would be very helpful to have similar behavior about empty values.
We ran into a problem, that made me create this issue: There's a project, called mongodbforms, that allows to create django forms from mongoengine documents.
ModelForm
field in django becomes required only whenblank==False
, so it's possible to forbid field to have empty values on database level and don't make it required in the form. And, since mongoengine field has only one attribute related to the nullability of the field, mongodbforms has to set required attribute of formfield according to required attribute of mongoengine document. Best example isBooleanField
. Once it's required, form cannot be submitted with unchecked checkbox of thisBooleanField
due to validation error. So it's impossible to useBooleanField
in mongoengine document with required set toTrue
in mongodbforms.The proposal is to add "blank" attribute to mongoengine document field with the same behavior as "blank" attribute in django model fields.