mirror of
https://github.com/inventree/InvenTree.git
synced 2026-04-03 10:01:07 +00:00
Add options for spectacular
This commit is contained in:
@@ -28,10 +28,9 @@ def get_spectacular_settings():
|
|||||||
'UserTypeEnum': 'users.models.UserProfile.UserType',
|
'UserTypeEnum': 'users.models.UserProfile.UserType',
|
||||||
'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',
|
||||||
|
'ParameterTemplateModelTypeEnum': 'common.models.ParameterTemplate.ModelChoices',
|
||||||
'DataImportSessionModelTypeEnum': 'importer.models.DataImportSession.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
|
# Allauth
|
||||||
'UnauthorizedStatus': [[401, 401]],
|
'UnauthorizedStatus': [[401, 401]],
|
||||||
'IsTrueEnum': [[True, True]],
|
'IsTrueEnum': [[True, True]],
|
||||||
|
|||||||
@@ -2387,6 +2387,11 @@ class ParameterTemplate(
|
|||||||
verbose_name = _('Parameter Template')
|
verbose_name = _('Parameter Template')
|
||||||
verbose_name_plural = _('Parameter Templates')
|
verbose_name_plural = _('Parameter Templates')
|
||||||
|
|
||||||
|
class ModelChoices(RenderChoices):
|
||||||
|
"""Model choices for parameters."""
|
||||||
|
|
||||||
|
choice_fnc = common.validators.parameter_template_model_options
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_api_url() -> str:
|
def get_api_url() -> str:
|
||||||
"""Return the API URL associated with the ParameterTemplate model."""
|
"""Return the API URL associated with the ParameterTemplate model."""
|
||||||
@@ -2574,6 +2579,11 @@ class Parameter(
|
|||||||
|
|
||||||
indexes = [models.Index(fields=['model_type', 'model_id'])]
|
indexes = [models.Index(fields=['model_type', 'model_id'])]
|
||||||
|
|
||||||
|
class ModelChoices(RenderChoices):
|
||||||
|
"""Model choices for parameters."""
|
||||||
|
|
||||||
|
choice_fnc = common.validators.parameter_model_options
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_api_url() -> str:
|
def get_api_url() -> str:
|
||||||
"""Return the API URL associated with the Parameter model."""
|
"""Return the API URL associated with the Parameter model."""
|
||||||
|
|||||||
@@ -9,6 +9,35 @@ import common.icons
|
|||||||
from common.settings import get_global_setting
|
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():
|
def attachment_model_types():
|
||||||
"""Return a list of valid attachment model choices."""
|
"""Return a list of valid attachment model choices."""
|
||||||
import InvenTree.models
|
import InvenTree.models
|
||||||
|
|||||||
Reference in New Issue
Block a user