mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Scratch that
This commit is contained in:
parent
b350a971a4
commit
b273dc613b
@ -88,58 +88,3 @@ class InvenTreeMetadata(SimpleMetadata):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
def get_field_info(self, field):
|
|
||||||
"""
|
|
||||||
Given an instance of a serializer field, return a dictionary
|
|
||||||
of metadata about it.
|
|
||||||
"""
|
|
||||||
|
|
||||||
field_info = OrderedDict()
|
|
||||||
|
|
||||||
field_info['type'] = self.label_lookup[field]
|
|
||||||
field_info['required'] = getattr(field, 'required', False)
|
|
||||||
|
|
||||||
if field_info['type'] == 'field':
|
|
||||||
|
|
||||||
# If the field is a 'ForeignKey' field
|
|
||||||
if isinstance(field, serializers.ModelSerializer): # or isinstance(field, serializers.PrimaryKeyRelatedField):
|
|
||||||
model = field.Meta.model
|
|
||||||
|
|
||||||
# Construct the 'table name' from the model
|
|
||||||
app_label = model._meta.app_label
|
|
||||||
tbl_label = model._meta.model_name
|
|
||||||
|
|
||||||
table = f"{app_label}_{tbl_label}"
|
|
||||||
field_info['model'] = table
|
|
||||||
|
|
||||||
print(field_info['type'], field, type(field))
|
|
||||||
|
|
||||||
attrs = [
|
|
||||||
'read_only', 'label', 'help_text',
|
|
||||||
'min_length', 'max_length',
|
|
||||||
'min_value', 'max_value'
|
|
||||||
]
|
|
||||||
|
|
||||||
for attr in attrs:
|
|
||||||
value = getattr(field, attr, None)
|
|
||||||
if value is not None and value != '':
|
|
||||||
field_info[attr] = force_str(value, strings_only=True)
|
|
||||||
|
|
||||||
if getattr(field, 'child', None):
|
|
||||||
field_info['child'] = self.get_field_info(field.child)
|
|
||||||
elif getattr(field, 'fields', None):
|
|
||||||
field_info['children'] = self.get_serializer_info(field)
|
|
||||||
|
|
||||||
if (not field_info.get('read_only') and
|
|
||||||
not isinstance(field, (serializers.RelatedField, serializers.ManyRelatedField)) and
|
|
||||||
hasattr(field, 'choices')):
|
|
||||||
field_info['choices'] = [
|
|
||||||
{
|
|
||||||
'value': choice_value,
|
|
||||||
'display_name': force_str(choice_name, strings_only=True)
|
|
||||||
}
|
|
||||||
for choice_value, choice_name in field.choices.items()
|
|
||||||
]
|
|
||||||
|
|
||||||
return field_info
|
|
Loading…
Reference in New Issue
Block a user