mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Automatically associate ''filters' with relations
This commit is contained in:
parent
e585079779
commit
f3ed05a09e
@ -97,6 +97,7 @@ class InvenTreeMetadata(SimpleMetadata):
|
||||
|
||||
model_fields = model_meta.get_field_info(ModelClass)
|
||||
|
||||
# Iterate through simple fields
|
||||
for name, field in model_fields.fields.items():
|
||||
|
||||
if field.has_default() and name in field_info.keys():
|
||||
@ -110,9 +111,25 @@ class InvenTreeMetadata(SimpleMetadata):
|
||||
continue
|
||||
|
||||
field_info[name]['default'] = default
|
||||
|
||||
# Iterate through relations
|
||||
for name, relation in model_fields.relations.items():
|
||||
|
||||
if relation.reverse:
|
||||
print("skipping reverse relation -", name)
|
||||
continue
|
||||
|
||||
print('filters:', name, relation.model_field.get_limit_choices_to())
|
||||
|
||||
continue
|
||||
# Extract and provide the "limit_choices_to" filters
|
||||
field_info[name]['filters'] = relation.model_field.get_limit_choices_to()
|
||||
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
print(field_info.keys())
|
||||
|
||||
return field_info
|
||||
|
||||
def get_field_info(self, field):
|
||||
|
@ -40,12 +40,34 @@
|
||||
|
||||
$('#new-company-2').click(function() {
|
||||
constructForm(
|
||||
'{% url "api-company-list" %}',
|
||||
'{% url "api-build-list" %}',
|
||||
{
|
||||
method: 'POST',
|
||||
fields: [
|
||||
'name',
|
||||
'description',
|
||||
title: '{% trans "Edit Part Details" %}',
|
||||
fields: {
|
||||
name: {
|
||||
onEdit: function() {
|
||||
console.log('Edited name field');
|
||||
}
|
||||
},
|
||||
description: {},
|
||||
category: {
|
||||
filters: {
|
||||
parent: 1,
|
||||
},
|
||||
secondary: {
|
||||
label: '{% trans "New Category" %}',
|
||||
},
|
||||
},
|
||||
active: {
|
||||
onEdit: function() {
|
||||
console.log('edited active field');
|
||||
}
|
||||
},
|
||||
purchaseable: {},
|
||||
salable: {},
|
||||
component: {},
|
||||
/*
|
||||
'website',
|
||||
'address',
|
||||
'phone',
|
||||
@ -54,7 +76,8 @@
|
||||
'is_supplier',
|
||||
'is_manufacturer',
|
||||
'is_customer',
|
||||
]
|
||||
*/
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user