Simplified PART and PROJECT APIs

This commit is contained in:
Oliver Walters 2017-04-14 15:25:10 +10:00
parent fe52610fcc
commit 37808f3834
5 changed files with 19 additions and 29 deletions

View File

@ -32,16 +32,11 @@ class PartSerializer(serializers.ModelSerializer):
'stock')
class PartCategoryBriefSerializer(serializers.ModelSerializer):
class PartCategorySerializer(serializers.ModelSerializer):
class Meta:
model = PartCategory
fields = ('pk',
'name',
'description')
children = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
class PartCategoryDetailSerializer(serializers.ModelSerializer):
parts = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
class Meta:
model = PartCategory
@ -49,7 +44,9 @@ class PartCategoryDetailSerializer(serializers.ModelSerializer):
'name',
'description',
'parent',
'path')
'path',
'children',
'parts')
class PartTemplateSerializer(serializers.ModelSerializer):

View File

@ -5,7 +5,7 @@ from rest_framework import generics, permissions
from InvenTree.models import FilterChildren
from .models import PartCategory, Part, PartParameter, PartParameterTemplate
from .serializers import PartSerializer
from .serializers import PartCategoryDetailSerializer
from .serializers import PartCategorySerializer
from .serializers import PartParameterSerializer
from .serializers import PartTemplateSerializer
@ -83,7 +83,7 @@ class PartCategoryDetail(generics.RetrieveUpdateDestroyAPIView):
""" Return information on a single PartCategory
"""
queryset = PartCategory.objects.all()
serializer_class = PartCategoryDetailSerializer
serializer_class = PartCategorySerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
@ -102,7 +102,7 @@ class PartCategoryList(generics.ListCreateAPIView):
return categories
queryset = PartCategory.objects.filter(parent=None)
serializer_class = PartCategoryDetailSerializer
serializer_class = PartCategorySerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)

View File

@ -29,17 +29,11 @@ class Project(models.Model):
name = models.CharField(max_length=100)
description = models.CharField(max_length=500, blank=True)
category = models.ForeignKey(ProjectCategory, on_delete=models.CASCADE)
category = models.ForeignKey(ProjectCategory, on_delete=models.CASCADE, related_name='projects')
def __str__(self):
return self.name
@property
def projectParts(self):
""" Return a list of all project parts associated with this project
"""
return self.projectpart_set.all()
class ProjectPartManager(models.Manager):
""" Manager for handling ProjectParts

View File

@ -26,14 +26,11 @@ class ProjectSerializer(serializers.ModelSerializer):
'category')
class ProjectCategoryBriefSerializer(serializers.ModelSerializer):
class ProjectCategorySerializer(serializers.ModelSerializer):
class Meta:
model = ProjectCategory
fields = ('pk', 'name', 'description')
children = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
class ProjectCategoryDetailSerializer(serializers.ModelSerializer):
projects = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
class Meta:
model = ProjectCategory
@ -41,4 +38,6 @@ class ProjectCategoryDetailSerializer(serializers.ModelSerializer):
'name',
'description',
'parent',
'path')
'path',
'children',
'projects')

View File

@ -3,7 +3,7 @@ from rest_framework import generics, permissions
from InvenTree.models import FilterChildren
from .models import ProjectCategory, Project, ProjectPart
from .serializers import ProjectSerializer
from .serializers import ProjectCategoryDetailSerializer
from .serializers import ProjectCategorySerializer
from .serializers import ProjectPartSerializer
@ -40,7 +40,7 @@ class ProjectCategoryDetail(generics.RetrieveUpdateAPIView):
"""
queryset = ProjectCategory.objects.all()
serializer_class = ProjectCategoryDetailSerializer
serializer_class = ProjectCategorySerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
@ -57,7 +57,7 @@ class ProjectCategoryList(generics.ListCreateAPIView):
return categories
serializer_class = ProjectCategoryDetailSerializer
serializer_class = ProjectCategorySerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)