mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-16 17:28:11 +00:00
Define GenericRelationship for linking model
This commit is contained in:
@@ -6,6 +6,7 @@ from string import Formatter
|
|||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
@@ -494,13 +495,23 @@ class InvenTreePermissionCheckMixin:
|
|||||||
return user.has_perm(perm)
|
return user.has_perm(perm)
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeParameterMixin(InvenTreePermissionCheckMixin):
|
class InvenTreeParameterMixin(InvenTreePermissionCheckMixin, models.Model):
|
||||||
"""Provides an abstracted class for managing parameters.
|
"""Provides an abstracted class for managing parameters.
|
||||||
|
|
||||||
Links the implementing model to the common.models.Parameter table,
|
Links the implementing model to the common.models.Parameter table,
|
||||||
and provides the following methods:
|
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
|
@property
|
||||||
def parameters(self) -> QuerySet:
|
def parameters(self) -> QuerySet:
|
||||||
"""Return a QuerySet containing all the Parameter instances for this model."""
|
"""Return a QuerySet containing all the Parameter instances for this model."""
|
||||||
|
|||||||
Reference in New Issue
Block a user