Added "Part"

- Has IPN (internal part number)
- Linked to a PartCategory
This commit is contained in:
Oliver Walters 2017-03-25 23:19:49 +11:00
parent bb4fc9820f
commit ffb9132de2
2 changed files with 18 additions and 3 deletions

View File

@ -1,5 +1,6 @@
from django.contrib import admin from django.contrib import admin
from .models import PartCategory from .models import PartCategory, Part
admin.site.register(Part)
admin.site.register(PartCategory) admin.site.register(PartCategory)

View File

@ -3,12 +3,26 @@ from __future__ import unicode_literals
from django.db import models from django.db import models
class PartCategory(models.Model): class PartCategory(models.Model):
name = models.CharField(max_length=128) name = models.CharField(max_length=100)
description = models.CharField(max_length=512) description = models.CharField(max_length=250)
parent = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True) parent = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True)
def __str__(self): def __str__(self):
if self.parent: if self.parent:
return str(self.parent) + "/" + self.name return str(self.parent) + "/" + self.name
else:
return self.name
class Part(models.Model):
name = models.CharField(max_length=100)
description = models.CharField(max_length=250, blank=True)
IPN = models.CharField(max_length=100, blank=True)
category = models.ForeignKey(PartCategory, on_delete=models.CASCADE)
def __str__(self):
if self.IPN:
return "{name} ({ipn})".format(
ipn = self.IPN,
name = self.name)
else: else:
return self.name return self.name