2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-03-16 09:01:30 +00:00

Add null choice to custom serializer class

This commit is contained in:
Oliver Walters
2025-12-03 05:51:00 +00:00
parent 49131dd969
commit 4f9474290f
2 changed files with 4 additions and 0 deletions

View File

@@ -756,6 +756,9 @@ class ContentTypeField(serializers.ChoiceField):
(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)
def to_representation(self, value):

View File

@@ -29,6 +29,7 @@ def get_spectacular_settings():
'TemplateModelTypeEnum': 'report.models.ReportTemplateBase.ModelChoices',
'AttachmentModelTypeEnum': 'common.models.Attachment.ModelChoices',
'ParameterModelTypeEnum': 'common.models.Parameter.ModelChoices',
'ParameterTemplateModelTypeEnum': 'common.models.ParameterTemplate.ModelChoices',
'DataImportSessionModelTypeEnum': 'importer.models.DataImportSession.ModelChoices',
# Allauth
'UnauthorizedStatus': [[401, 401]],