2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-12-16 09:18:10 +00:00

Define GenericRelationship for linking model

This commit is contained in:
Oliver Walters
2025-11-25 00:54:14 +00:00
parent 6e1292aa62
commit 48931d0061

View File

@@ -6,6 +6,7 @@ from string import Formatter
from typing import Any, Optional
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.fields import GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.db import models
@@ -494,13 +495,23 @@ class InvenTreePermissionCheckMixin:
return user.has_perm(perm)
class InvenTreeParameterMixin(InvenTreePermissionCheckMixin):
class InvenTreeParameterMixin(InvenTreePermissionCheckMixin, models.Model):
"""Provides an abstracted class for managing parameters.
Links the implementing model to the common.models.Parameter table,
and provides the following methods:
"""
class Meta:
"""Metaclass options for InvenTreeParameterMixin."""
abstract = True
# Define a reverse relation to the Parameter model
parameters_list = GenericRelation(
'common.Parameter', content_type_field='model_type', object_id_field='model_id'
)
@property
def parameters(self) -> QuerySet:
"""Return a QuerySet containing all the Parameter instances for this model."""