Commit cf3a95c1 authored by antoine.lizee's avatar antoine.lizee

enh: keep allow_blank=False for MANYTOONE that are required

parent f7825f99
......@@ -105,15 +105,16 @@ class AdminModelConverter(ModelConverterBase):
# determine optional/required, or respect existing
requirement_options = (validators.Optional, validators.InputRequired)
if not any(isinstance(v, requirement_options) for v in kwargs['validators']):
if property_is_association_proxy or column.nullable or prop.direction.name != 'MANYTOONE':
requirement_validator_specified = any(isinstance(v, requirement_options) for v in kwargs['validators'])
if property_is_association_proxy or column.nullable or prop.direction.name != 'MANYTOONE':
kwargs['allow_blank'] = True
if not requirement_validator_specified:
kwargs['validators'].append(validators.Optional())
else:
else:
kwargs['allow_blank'] = False
if not requirement_validator_specified:
kwargs['validators'].append(validators.InputRequired())
# Never prepopulate relation widgets:
kwargs['allow_blank'] = True
# Override field type if necessary
override = self._get_field_override(prop.key)
if override:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment