add doc for generic mixin

This commit is contained in:
Matthias 2022-04-05 00:23:09 +02:00
parent 23f57bec19
commit 586812e5c6
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -103,8 +103,34 @@ class PluginConfig(models.Model):
class GenericSettingClassMixin:
"""
This mixin can be used to add reference keys to static properties
Sample:
```python
class SampleSetting(GenericSettingClassMixin, common.models.BaseInvenTreeSetting):
class Meta:
unique_together = [
('sample', 'key'),
]
REFERENCE_NAME = 'sample'
@classmethod
def get_setting_definition(cls, key, **kwargs):
# mysampledict contains the dict with all settings for this SettingClass - this could also be a dynamic lookup
kwargs['settings'] = mysampledict
return super().get_setting_definition(key, **kwargs)
sample = models.charKey( # the name for this field is the additonal key and must be set in the Meta class an REFERENCE_NAME
max_length=256,
verbose_name=_('sample')
)
```
"""
# region generic helpers
REFERENCE_NAME = None
def _get_reference(self):