mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
commit
af79c937fd
@ -3,41 +3,25 @@ from rest_framework import serializers
|
||||
from .models import Part, PartCategory, PartParameter
|
||||
|
||||
|
||||
class ParameterSerializer(serializers.ModelSerializer):
|
||||
class PartParameterSerializer(serializers.ModelSerializer):
|
||||
""" Serializer for a PartParameter
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = PartParameter
|
||||
fields = ('pk',
|
||||
'part',
|
||||
'template',
|
||||
'name',
|
||||
'value',
|
||||
'units')
|
||||
|
||||
|
||||
class PartDetailSerializer(serializers.ModelSerializer):
|
||||
class PartSerializer(serializers.ModelSerializer):
|
||||
""" Serializer for complete detail information of a part.
|
||||
Used when displaying all details of a single component.
|
||||
"""
|
||||
|
||||
params = ParameterSerializer(source='parameters', many=True)
|
||||
|
||||
class Meta:
|
||||
model = Part
|
||||
fields = ('pk',
|
||||
'name',
|
||||
'IPN',
|
||||
'description',
|
||||
'category',
|
||||
'stock',
|
||||
'params')
|
||||
|
||||
|
||||
class PartBriefSerializer(serializers.ModelSerializer):
|
||||
""" Serializer for displaying overview of a part.
|
||||
Used e.g. for displaying list of parts in a category.
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Part
|
||||
fields = ('pk',
|
||||
@ -60,7 +44,7 @@ class PartCategoryBriefSerializer(serializers.ModelSerializer):
|
||||
class PartCategoryDetailSerializer(serializers.ModelSerializer):
|
||||
|
||||
# List of parts in this category
|
||||
parts = PartBriefSerializer(many=True)
|
||||
parts = PartSerializer(many=True)
|
||||
|
||||
# List of child categories under this one
|
||||
children = PartCategoryBriefSerializer(many=True)
|
||||
|
@ -6,6 +6,9 @@ urlpatterns = [
|
||||
# Single part detail
|
||||
url(r'^(?P<pk>[0-9]+)/$', views.PartDetail.as_view()),
|
||||
|
||||
# Part parameters list
|
||||
url(r'^(?P<pk>[0-9]+)/parameters/$', views.PartParameters.as_view()),
|
||||
|
||||
# Part category detail
|
||||
url(r'^category/(?P<pk>[0-9]+)/$', views.PartCategoryDetail.as_view()),
|
||||
|
||||
|
@ -1,20 +1,30 @@
|
||||
from rest_framework import generics
|
||||
|
||||
from .models import PartCategory, Part
|
||||
from .serializers import PartBriefSerializer, PartDetailSerializer
|
||||
from .models import PartCategory, Part, PartParameter
|
||||
from .serializers import PartSerializer
|
||||
from .serializers import PartCategoryBriefSerializer, PartCategoryDetailSerializer
|
||||
from .serializers import PartParameterSerializer
|
||||
|
||||
|
||||
class PartDetail(generics.RetrieveAPIView):
|
||||
|
||||
queryset = Part.objects.all()
|
||||
serializer_class = PartDetailSerializer
|
||||
serializer_class = PartSerializer
|
||||
|
||||
|
||||
class PartParameters(generics.ListAPIView):
|
||||
|
||||
def get_queryset(self):
|
||||
part_id = self.kwargs['pk']
|
||||
return PartParameter.objects.filter(part=part_id)
|
||||
|
||||
serializer_class = PartParameterSerializer
|
||||
|
||||
|
||||
class PartList(generics.ListAPIView):
|
||||
|
||||
queryset = Part.objects.all()
|
||||
serializer_class = PartBriefSerializer
|
||||
serializer_class = PartSerializer
|
||||
|
||||
|
||||
class PartCategoryDetail(generics.RetrieveAPIView):
|
||||
|
@ -12,7 +12,7 @@ class ProjectAdmin(admin.ModelAdmin):
|
||||
|
||||
|
||||
class ProjectPartAdmin(admin.ModelAdmin):
|
||||
list_display = ('part', 'project', 'quantity')
|
||||
list_display = ('part', 'project', 'quantity', 'output')
|
||||
|
||||
|
||||
class ProjectRunAdmin(admin.ModelAdmin):
|
||||
|
@ -64,6 +64,10 @@ class ProjectPart(models.Model):
|
||||
default=OVERAGE_ABSOLUTE,
|
||||
choices=OVARAGE_CODES.items())
|
||||
|
||||
# Set if the part is generated by the project,
|
||||
# rather than being consumed by the project
|
||||
output = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return "{quan} x {name}".format(
|
||||
name=self.part.name,
|
||||
|
@ -12,7 +12,8 @@ class ProjectPartSerializer(serializers.ModelSerializer):
|
||||
'project',
|
||||
'quantity',
|
||||
'overage',
|
||||
'overage_type')
|
||||
'overage_type',
|
||||
'output')
|
||||
|
||||
|
||||
class ProjectBriefSerializer(serializers.ModelSerializer):
|
||||
|
Loading…
Reference in New Issue
Block a user