Updated part parameter

This commit is contained in:
Oliver Walters 2017-03-29 15:45:50 +11:00
parent 4dc0179484
commit 4fafe93d9c
2 changed files with 31 additions and 5 deletions

View File

@ -1,6 +1,6 @@
from django.contrib import admin from django.contrib import admin
from .models import PartCategory, Part, PartParameter, PartParameterTemplate from .models import PartCategory, Part, PartParameter, PartParameterTemplate, CategoryParameterLink
class PartAdmin(admin.ModelAdmin): class PartAdmin(admin.ModelAdmin):
@ -14,7 +14,7 @@ class PartCategoryAdmin(admin.ModelAdmin):
class ParameterTemplateAdmin(admin.ModelAdmin): class ParameterTemplateAdmin(admin.ModelAdmin):
list_display = ('name', 'units', 'category') list_display = ('name', 'units', 'format')
class ParameterAdmin(admin.ModelAdmin): class ParameterAdmin(admin.ModelAdmin):
@ -26,3 +26,4 @@ admin.site.register(PartCategory, PartCategoryAdmin)
admin.site.register(PartParameter, ParameterAdmin) admin.site.register(PartParameter, ParameterAdmin)
admin.site.register(PartParameterTemplate, ParameterTemplateAdmin) admin.site.register(PartParameterTemplate, ParameterTemplateAdmin)
admin.site.register(CategoryParameterLink)

View File

@ -82,9 +82,6 @@ class PartParameterTemplate(models.Model):
ready to be copied for use with a given Part. ready to be copied for use with a given Part.
A PartParameterTemplate can be optionally associated with a PartCategory A PartParameterTemplate can be optionally associated with a PartCategory
""" """
category = models.ForeignKey(PartCategory, on_delete=models.CASCADE, blank=True, null=True)
name = models.CharField(max_length=20) name = models.CharField(max_length=20)
description = models.CharField(max_length=100, blank=True) description = models.CharField(max_length=100, blank=True)
units = models.CharField(max_length=10, blank=True) units = models.CharField(max_length=10, blank=True)
@ -93,6 +90,18 @@ class PartParameterTemplate(models.Model):
default_min = models.CharField(max_length=50, blank=True) default_min = models.CharField(max_length=50, blank=True)
default_max = models.CharField(max_length=50, blank=True) default_max = models.CharField(max_length=50, blank=True)
# Parameter format
PARAM_NUMERIC = 10
PARAM_TEXT = 20
PARAM_BOOL = 30
format = models.IntegerField(
default=PARAM_NUMERIC,
choices=[
(PARAM_NUMERIC, "Numeric"),
(PARAM_TEXT, "Text"),
(PARAM_BOOL, "Boolean")])
def __str__(self): def __str__(self):
return "{name} ({units})".format( return "{name} ({units})".format(
name=self.name, name=self.name,
@ -101,7 +110,23 @@ class PartParameterTemplate(models.Model):
class Meta: class Meta:
verbose_name = "Parameter Template" verbose_name = "Parameter Template"
verbose_name_plural = "Parameter Templates" verbose_name_plural = "Parameter Templates"
class CategoryParameterLink(models.Model):
""" Links a PartParameterTemplate to a PartCategory
"""
category = models.ForeignKey(PartCategory, on_delete=models.CASCADE)
template = models.ForeignKey(PartParameterTemplate, on_delete=models.CASCADE)
def __str__(self):
return "{name} - {cat}".format(
name=self.template.name,
cat=self.category)
class Meta:
verbose_name = "Category Parameter"
verbose_name_plural = "Category Parameters"
class PartParameter(models.Model): class PartParameter(models.Model):
""" PartParameter is associated with a single part """ PartParameter is associated with a single part