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

Add options for spectacular

This commit is contained in:
Oliver Walters
2025-12-02 03:19:55 +00:00
parent aaf6a97d71
commit 1e2fdd71c7
3 changed files with 41 additions and 3 deletions

View File

@@ -28,10 +28,9 @@ def get_spectacular_settings():
'UserTypeEnum': 'users.models.UserProfile.UserType',
'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',
# Deconflict fields which use model_type ContentType fields
'common.models.Parameter.model_type': 'ParameterModelTypeEnum',
'common.models.ParameterTemplate.model_type': 'ParameterTemplateModelTypeEnum',
# Allauth
'UnauthorizedStatus': [[401, 401]],
'IsTrueEnum': [[True, True]],

View File

@@ -2387,6 +2387,11 @@ class ParameterTemplate(
verbose_name = _('Parameter Template')
verbose_name_plural = _('Parameter Templates')
class ModelChoices(RenderChoices):
"""Model choices for parameters."""
choice_fnc = common.validators.parameter_template_model_options
@staticmethod
def get_api_url() -> str:
"""Return the API URL associated with the ParameterTemplate model."""
@@ -2574,6 +2579,11 @@ class Parameter(
indexes = [models.Index(fields=['model_type', 'model_id'])]
class ModelChoices(RenderChoices):
"""Model choices for parameters."""
choice_fnc = common.validators.parameter_model_options
@staticmethod
def get_api_url() -> str:
"""Return the API URL associated with the Parameter model."""

View File

@@ -9,6 +9,35 @@ import common.icons
from common.settings import get_global_setting
def parameter_model_types():
"""Return a list of valid parameter model choices."""
import InvenTree.models
return list(
InvenTree.helpers_model.getModelsWithMixin(
InvenTree.models.InvenTreeParameterMixin
)
)
def parameter_model_options():
"""Return a list of options for models which support parameters."""
return [
(model.__name__.lower(), model._meta.verbose_name)
for model in parameter_model_types()
]
def parameter_template_model_options():
"""Return a list of options for models which support parameter templates."""
options = [
(model.__name__.lower(), model._meta.verbose_name)
for model in parameter_model_types()
]
return [(None, _('All models')), *options]
def attachment_model_types():
"""Return a list of valid attachment model choices."""
import InvenTree.models