From 13ca076f42b288ef4bc1ab2c5ab07a3a8ce56b59 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 9 Jul 2021 00:29:36 +1000 Subject: [PATCH] Fix for form rendering of "required" fields with a default value - Force the "required" parameter to be set --- InvenTree/InvenTree/metadata.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/InvenTree/InvenTree/metadata.py b/InvenTree/InvenTree/metadata.py index 92948653b0..c22b39dc43 100644 --- a/InvenTree/InvenTree/metadata.py +++ b/InvenTree/InvenTree/metadata.py @@ -153,6 +153,11 @@ class InvenTreeMetadata(SimpleMetadata): if 'default' not in field_info and not field.default == empty: field_info['default'] = field.get_default() + # Force non-nullable fields to read as "required" + # (even if there is a default value!) + if not field.allow_null and not (hasattr(field, 'allow_blank') and field.allow_blank): + field_info['required'] = True + # Introspect writable related fields if field_info['type'] == 'field' and not field_info['read_only']: