Reputation: 134
I wonder if there is a possibility of changing default value of the "required" parameter for all fields.
Almost all the fields of my models are required and so I have to put the parameter required=True
for almost all the fields, it's a little painful.
Upvotes: 1
Views: 236
Reputation: 7668
You can implement your own Field classes. For example:
from mongoengine import fields
class StringField(fields.StringField):
def __init__(self, regex=None, max_length=None, min_length=None, default=True, **kwargs):
super(StringField, self).__init__(regex, max_length, min_length, default=default, **kwargs)
That will allow you to have a StringField class that has the default value of required
set to True
. Unfortunately you have to do that for every Field class that you use.
Upvotes: 1