Merge pull request #1 from SchrodingersGat/master

Improving model admin views
This commit is contained in:
Oliver 2017-03-28 18:23:45 +11:00 committed by GitHub
commit b288ac0a45
9 changed files with 74 additions and 22 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,15 @@ 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', 'description')
admin.site.register(Part, PartAdmin)
admin.site.register(PartCategory, PartCategoryAdmin)

View File

@ -20,6 +20,9 @@ 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)
trackable = models.BooleanField(default=False)
def __str__(self):
if self.IPN:
@ -33,4 +36,18 @@ class Part(models.Model):
verbose_name = "Part"
verbose_name_plural = "Parts"
class PartRevision(models.Model):
""" A PartRevision represents a change-notification to a Part
A Part may go through several revisions in its lifetime,
which should be tracked.
UniqueParts can have a single associated PartRevision
"""
part = models.ForeignKey(Part, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
description = models.CharField(max_length=500)
revision_date = models.DateField(auto_now_add = True)
def __str__(self):
return self.name

View File

@ -1,6 +1,6 @@
{# Construct the category path #}
<a href="../">Category</a>/
{% for path_item in category.path %}
{% for path_item in category.parentpath %}
<a href="../{{ path_item.pk }}">{{ path_item.name }}</a>/
{% endfor %}

View File

@ -2,6 +2,15 @@ from django.contrib import admin
from .models import ProjectCategory, Project, ProjectPart
admin.site.register(ProjectCategory)
admin.site.register(Project)
admin.site.register(ProjectPart)
class ProjectCategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'path', 'description')
class ProjectAdmin(admin.ModelAdmin):
list_display = ('name', 'description', 'category')
class ProjectPartAdmin(admin.ModelAdmin):
list_display = ('part', 'project', 'quantity')
admin.site.register(ProjectCategory, ProjectCategoryAdmin)
admin.site.register(Project, ProjectAdmin)
admin.site.register(ProjectPart, ProjectPartAdmin)

View File

@ -2,5 +2,11 @@ from django.contrib import admin
from .models import Warehouse, StockItem
admin.site.register(Warehouse)
admin.site.register(StockItem)
class WarehouseAdmin(admin.ModelAdmin):
list_display = ('name', 'path', 'description')
class StockItemAdmin(admin.ModelAdmin):
list_display = ('part', 'quantity', 'location', 'updated')
admin.site.register(Warehouse, WarehouseAdmin)
admin.site.register(StockItem, StockItemAdmin)

View File

@ -2,5 +2,8 @@ from django.contrib import admin
from .models import Supplier, SupplierPart
admin.site.register(Supplier)
class SupplierAdmin(admin.ModelAdmin):
list_display=('name','URL','contact')
admin.site.register(Supplier, SupplierAdmin)
admin.site.register(SupplierPart)

View File

@ -2,4 +2,7 @@ from django.contrib import admin
from .models import UniquePart
admin.site.register(UniquePart)
class UniquePartAdmin(admin.ModelAdmin):
list_display = ('part', 'revision', 'serial', 'creation_date')
admin.site.register(UniquePart, UniquePartAdmin)

View File

@ -3,7 +3,7 @@ from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
from part.models import Part
from part.models import Part, PartRevision
class UniquePart(models.Model):
""" A unique instance of a Part object.
@ -12,11 +12,20 @@ class UniquePart(models.Model):
"""
part = models.ForeignKey(Part, on_delete=models.CASCADE)
created = models.DateField(auto_now_add=True,
revision = models.ForeignKey(PartRevision,
on_delete=models.CASCADE,
blank=True,
null=True)
creation_date = models.DateField(auto_now_add=True,
editable=False)
serial = models.IntegerField()
createdBy = models.ForeignKey(User)
def __str__(self):
return self.part.name
class PartTrackingInfo(models.Model):
""" Single data-point in the life of a UniquePart