mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
make genericref simpler
This commit is contained in:
parent
17127e914d
commit
164a8acf33
@ -112,33 +112,28 @@ class GenericReferencedSettingSerializer(SettingsSerializer):
|
|||||||
MODEL = None
|
MODEL = None
|
||||||
EXTRA_FIELDS = None
|
EXTRA_FIELDS = None
|
||||||
|
|
||||||
def __init__(self, instance=None, data=..., **kwargs):
|
def __init__(self, **kwargs):
|
||||||
"""Init overrides the Meta class to make it dynamic"""
|
"""Init overrides the Meta class to make it dynamic"""
|
||||||
# set Meta class
|
class CustomMeta:
|
||||||
self.Meta = self.CustomMeta
|
"""Scaffold for custom Meta class"""
|
||||||
self.Meta.model = self.MODEL
|
fields = [
|
||||||
|
'pk',
|
||||||
|
'key',
|
||||||
|
'value',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'type',
|
||||||
|
'choices',
|
||||||
|
]
|
||||||
|
|
||||||
|
# set Meta class
|
||||||
|
self.Meta = CustomMeta
|
||||||
|
self.Meta.model = self.MODEL
|
||||||
# extend the fields
|
# extend the fields
|
||||||
if not self.CustomMeta.DEFINED:
|
self.Meta.fields.extend(self.EXTRA_FIELDS)
|
||||||
self.Meta.fields.extend(self.EXTRA_FIELDS)
|
|
||||||
self.CustomMeta.DEFINED = True
|
|
||||||
|
|
||||||
# resume operations
|
# resume operations
|
||||||
super().__init__(instance, data, **kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
class CustomMeta:
|
|
||||||
"""Scaffold for custom Meta class"""
|
|
||||||
DEFINED: bool = False
|
|
||||||
|
|
||||||
fields = [
|
|
||||||
'pk',
|
|
||||||
'key',
|
|
||||||
'value',
|
|
||||||
'name',
|
|
||||||
'description',
|
|
||||||
'type',
|
|
||||||
'choices',
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class NotificationMessageSerializer(InvenTreeModelSerializer):
|
class NotificationMessageSerializer(InvenTreeModelSerializer):
|
||||||
|
Loading…
Reference in New Issue
Block a user