mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Copy 'help_text' through from the model field if it is not defined for the serializer field
This commit is contained in:
parent
35bd6ce927
commit
1bde26a7be
@ -118,20 +118,31 @@ class InvenTreeMetadata(SimpleMetadata):
|
|||||||
# Iterate through simple fields
|
# Iterate through simple fields
|
||||||
for name, field in model_fields.fields.items():
|
for name, field in model_fields.fields.items():
|
||||||
|
|
||||||
if field.has_default() and name in serializer_info.keys():
|
if name in serializer_info.keys():
|
||||||
|
|
||||||
default = field.default
|
if field.has_default():
|
||||||
|
|
||||||
if callable(default):
|
default = field.default
|
||||||
try:
|
|
||||||
default = default()
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
|
|
||||||
serializer_info[name]['default'] = default
|
if callable(default):
|
||||||
|
try:
|
||||||
|
default = default()
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
elif name in model_default_values:
|
serializer_info[name]['default'] = default
|
||||||
serializer_info[name]['default'] = model_default_values[name]
|
|
||||||
|
elif name in model_default_values:
|
||||||
|
serializer_info[name]['default'] = model_default_values[name]
|
||||||
|
|
||||||
|
# Attributes to copy from the model to the field (if they don't exist)
|
||||||
|
attributes = ['help_text']
|
||||||
|
|
||||||
|
for attr in attributes:
|
||||||
|
if attr not in serializer_info[name]:
|
||||||
|
|
||||||
|
if hasattr(field, attr):
|
||||||
|
serializer_info[name][attr] = getattr(field, attr)
|
||||||
|
|
||||||
# Iterate through relations
|
# Iterate through relations
|
||||||
for name, relation in model_fields.relations.items():
|
for name, relation in model_fields.relations.items():
|
||||||
|
Loading…
Reference in New Issue
Block a user