diff --git a/InvenTree/part/admin.py b/InvenTree/part/admin.py index 5c8211e2be..eb0c32e751 100644 --- a/InvenTree/part/admin.py +++ b/InvenTree/part/admin.py @@ -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) \ No newline at end of file +admin.site.register(PartCategory, PartCategoryAdmin) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index fab3c866bc..01e640febf 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -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 \ No newline at end of file + return self.name diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 6520785a82..49ee7de40f 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -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 \ No newline at end of file + serializer_class = PartCategorySerializer