@@ -95,6 +95,9 @@ def get_field_kwargs(field_name, model_field):
95
95
(hasattr (models , 'JSONField' ) and isinstance (model_field , models .JSONField )):
96
96
kwargs ['style' ] = {'base_template' : 'textarea.html' }
97
97
98
+ if model_field .null :
99
+ kwargs ['allow_null' ] = True
100
+
98
101
if isinstance (model_field , models .AutoField ) or not model_field .editable :
99
102
# If this field is read-only, then return early.
100
103
# Further keyword arguments are not valid.
@@ -104,9 +107,6 @@ def get_field_kwargs(field_name, model_field):
104
107
if model_field .has_default () or model_field .blank or model_field .null :
105
108
kwargs ['required' ] = False
106
109
107
- if model_field .null :
108
- kwargs ['allow_null' ] = True
109
-
110
110
if model_field .blank and (isinstance (model_field , (models .CharField , models .TextField ))):
111
111
kwargs ['allow_blank' ] = True
112
112
@@ -263,15 +263,15 @@ def get_relation_kwargs(field_name, relation_info):
263
263
if not model_field .editable :
264
264
kwargs ['read_only' ] = True
265
265
kwargs .pop ('queryset' , None )
266
+ if model_field .null :
267
+ kwargs ['allow_null' ] = True
266
268
if kwargs .get ('read_only' , False ):
267
269
# If this field is read-only, then return early.
268
270
# No further keyword arguments are valid.
269
271
return kwargs
270
272
271
273
if model_field .has_default () or model_field .blank or model_field .null :
272
274
kwargs ['required' ] = False
273
- if model_field .null :
274
- kwargs ['allow_null' ] = True
275
275
if model_field .validators :
276
276
kwargs ['validators' ] = model_field .validators
277
277
if getattr (model_field , 'unique' , False ):
0 commit comments