2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 04:55:44 +00:00

Move Meta class to top of class definition (#4363)

This commit is contained in:
Oliver
2023-02-18 18:51:00 +11:00
committed by GitHub
parent 139274f356
commit cc2e7ee8a5
27 changed files with 1085 additions and 1084 deletions

View File

@ -562,6 +562,14 @@ class Owner(models.Model):
owner: Returns the Group or User instance combining the owner_type and owner_id fields
"""
class Meta:
"""Metaclass defines extra model properties"""
# Ensure all owners are unique
constraints = [
UniqueConstraint(fields=['owner_type', 'owner_id'],
name='unique_owner')
]
@classmethod
def get_owners_matching_user(cls, user):
"""Return all "owner" objects matching the provided user.
@ -594,14 +602,6 @@ class Owner(models.Model):
"""Returns the API endpoint URL associated with the Owner model"""
return reverse('api-owner-list')
class Meta:
"""Metaclass defines extra model properties"""
# Ensure all owners are unique
constraints = [
UniqueConstraint(fields=['owner_type', 'owner_id'],
name='unique_owner')
]
owner_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, null=True, blank=True)
owner_id = models.PositiveIntegerField(null=True, blank=True)

View File

@ -12,10 +12,6 @@ from .models import Owner
class OwnerSerializer(InvenTreeModelSerializer):
"""Serializer for an "Owner" (either a "user" or a "group")"""
name = serializers.CharField(read_only=True)
label = serializers.CharField(read_only=True)
class Meta:
"""Metaclass defines serializer fields."""
model = Owner
@ -26,6 +22,10 @@ class OwnerSerializer(InvenTreeModelSerializer):
'label',
]
name = serializers.CharField(read_only=True)
label = serializers.CharField(read_only=True)
class GroupSerializer(InvenTreeModelSerializer):
"""Serializer for a 'Group'"""