mirror of
https://github.com/inventree/InvenTree.git
synced 2026-04-04 02:21:18 +00:00
Add null choice to custom serializer class
This commit is contained in:
@@ -756,6 +756,9 @@ class ContentTypeField(serializers.ChoiceField):
|
|||||||
(f'{ct.app_label}.{ct.model}', str(ct)) for ct in content_types
|
(f'{ct.app_label}.{ct.model}', str(ct)) for ct in content_types
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if kwargs.get('allow_null') or kwargs.get('allow_blank'):
|
||||||
|
kwargs['choices'] = [('', '---------'), *kwargs['choices']]
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ def get_spectacular_settings():
|
|||||||
'TemplateModelTypeEnum': 'report.models.ReportTemplateBase.ModelChoices',
|
'TemplateModelTypeEnum': 'report.models.ReportTemplateBase.ModelChoices',
|
||||||
'AttachmentModelTypeEnum': 'common.models.Attachment.ModelChoices',
|
'AttachmentModelTypeEnum': 'common.models.Attachment.ModelChoices',
|
||||||
'ParameterModelTypeEnum': 'common.models.Parameter.ModelChoices',
|
'ParameterModelTypeEnum': 'common.models.Parameter.ModelChoices',
|
||||||
|
'ParameterTemplateModelTypeEnum': 'common.models.ParameterTemplate.ModelChoices',
|
||||||
'DataImportSessionModelTypeEnum': 'importer.models.DataImportSession.ModelChoices',
|
'DataImportSessionModelTypeEnum': 'importer.models.DataImportSession.ModelChoices',
|
||||||
# Allauth
|
# Allauth
|
||||||
'UnauthorizedStatus': [[401, 401]],
|
'UnauthorizedStatus': [[401, 401]],
|
||||||
|
|||||||
Reference in New Issue
Block a user