peppa pig

This commit is contained in:
Oliver Walters 2017-03-28 23:31:41 +11:00
parent 14f60e1292
commit b5dc22f33a
3 changed files with 15 additions and 18 deletions

View File

@ -2,15 +2,15 @@ from django.contrib import admin
from .models import PartCategory, Part
class PartAdmin(admin.ModelAdmin):
list_display = ('name', 'IPN', 'stock', 'category')
# Custom form for PartCategory
class PartCategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'path', 'description')
admin.site.register(Part, PartAdmin)
admin.site.register(PartCategory, PartCategoryAdmin)
admin.site.register(PartCategory, PartCategoryAdmin)

View File

@ -7,11 +7,10 @@ from django.core.exceptions import ObjectDoesNotExist
from InvenTree.models import InvenTreeTree
class PartCategory(InvenTreeTree):
class PartCategory(InvenTreeTree):
""" PartCategory provides hierarchical organization of Part objects.
"""
class Meta:
verbose_name = "Part Category"
verbose_name_plural = "Part Categories"
@ -28,21 +27,18 @@ class Part(models.Model):
units = models.CharField(max_length=20, default="pcs", blank=True)
trackable = models.BooleanField(default=False)
def __str__(self):
if self.IPN:
return "{name} ({ipn})".format(
ipn = self.IPN,
name = self.name)
ipn=self.IPN,
name=self.name)
else:
return self.name
class Meta:
verbose_name = "Part"
verbose_name_plural = "Parts"
@property
def stock_list(self):
""" Return a list of all stock objects associated with this part
@ -50,7 +46,6 @@ class Part(models.Model):
return self.stockitem_set.all()
@property
def stock(self):
""" Return the total stock quantity for this part.
@ -64,7 +59,6 @@ class Part(models.Model):
result = stocks.aggregate(total=Sum('quantity'))
return result['total']
@property
def projects(self):
""" Return a list of unique projects that this part is associated with
@ -82,7 +76,7 @@ class Part(models.Model):
return projects
class PartRevision(models.Model):
""" A PartRevision represents a change-notification to a Part
A Part may go through several revisions in its lifetime,
@ -96,6 +90,5 @@ class PartRevision(models.Model):
description = models.CharField(max_length=500)
revision_date = models.DateField(auto_now_add = True)
def __str__(self):
return self.name
return self.name

View File

@ -9,22 +9,26 @@ from .serializers import PartSerializer, PartCategorySerializer
def index(request):
return HttpResponse("Hello world. This is the parts page")
class PartDetail(generics.RetrieveAPIView):
queryset = Part.objects.all()
serializer_class = PartSerializer
class PartList(generics.ListAPIView):
queryset = Part.objects.all()
serializer_class = PartSerializer
class PartCategoryDetail(generics.RetrieveAPIView):
queryset = PartCategory.objects.all()
serializer_class = PartCategorySerializer
class PartCategoryList(generics.ListAPIView):
queryset = PartCategory.objects.all()
serializer_class = PartCategorySerializer
serializer_class = PartCategorySerializer