make genericref simpler

This commit is contained in:
Matthias 2022-05-05 01:31:19 +02:00
parent 17127e914d
commit 164a8acf33
No known key found for this signature in database
GPG Key ID: AB6D0E6C4CB65093

View File

@ -112,24 +112,10 @@ class GenericReferencedSettingSerializer(SettingsSerializer):
MODEL = None
EXTRA_FIELDS = None
def __init__(self, instance=None, data=..., **kwargs):
def __init__(self, **kwargs):
"""Init overrides the Meta class to make it dynamic"""
# set Meta class
self.Meta = self.CustomMeta
self.Meta.model = self.MODEL
# extend the fields
if not self.CustomMeta.DEFINED:
self.Meta.fields.extend(self.EXTRA_FIELDS)
self.CustomMeta.DEFINED = True
# resume operations
super().__init__(instance, data, **kwargs)
class CustomMeta:
"""Scaffold for custom Meta class"""
DEFINED: bool = False
fields = [
'pk',
'key',
@ -140,6 +126,15 @@ class GenericReferencedSettingSerializer(SettingsSerializer):
'choices',
]
# set Meta class
self.Meta = CustomMeta
self.Meta.model = self.MODEL
# extend the fields
self.Meta.fields.extend(self.EXTRA_FIELDS)
# resume operations
super().__init__(**kwargs)
class NotificationMessageSerializer(InvenTreeModelSerializer):
"""