mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improved admin view for part
This commit is contained in:
parent
5420f83114
commit
492c651324
@ -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:
|
||||
|
@ -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)
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user