Improved admin view for part

This commit is contained in:
Oliver Walters 2017-03-28 17:49:01 +11:00
parent 5420f83114
commit 492c651324
3 changed files with 17 additions and 11 deletions

View File

@ -61,7 +61,7 @@ class InvenTreeTree(models.Model):
return acceptable
@property
def path(self):
def parentpath(self):
""" Return the parent path of this category
Todo:
@ -70,11 +70,16 @@ class InvenTreeTree(models.Model):
"""
if self.parent:
return self.parent.path + [self.parent]
return self.parent.parentpath + [self.parent]
else:
return []
return parent_path
@property
def path(self):
if self.parent:
return "/".join([p.name for p in self.parentpath]) + "/" + self.name
else:
return self.name
def __setattr__(self, attrname, val):
""" Custom Attribute Setting function
@ -118,10 +123,7 @@ class InvenTreeTree(models.Model):
This is recursive - Make it not so.
"""
if self.parent:
return "/".join([p.name for p in self.path]) + "/" + self.name
else:
return self.name
return self.path
class Meta:

View File

@ -2,12 +2,14 @@ from django.contrib import admin
from .models import PartCategory, Part
admin.site.register(Part)
class PartAdmin(admin.ModelAdmin):
list_display = ('name', 'IPN', 'category')
# Custom form for PartCategory
class PartCategoryAdmin(admin.ModelAdmin):
# TODO - Only let valid parents be displayed
pass
list_display = ('name', 'path')
admin.site.register(Part, PartAdmin)
admin.site.register(PartCategory, PartCategoryAdmin)

View File

@ -20,6 +20,8 @@ class Part(models.Model):
description = models.CharField(max_length=250, blank=True)
IPN = models.CharField(max_length=100, blank=True)
category = models.ForeignKey(PartCategory, on_delete=models.CASCADE)
minimum_stock = models.IntegerField(default=0)
units = models.CharField(max_length=20, default="pcs", blank=True)
def __str__(self):
if self.IPN: