diff --git a/shimatta_kenkyusho/parts/admin.py b/shimatta_kenkyusho/parts/admin.py index 046e01b..95de51e 100644 --- a/shimatta_kenkyusho/parts/admin.py +++ b/shimatta_kenkyusho/parts/admin.py @@ -9,6 +9,7 @@ admin.site.register(parts_models.Manufacturer) admin.site.register(parts_models.Storage) admin.site.register(parts_models.Stock) admin.site.register(parts_models.ComponentParameter) +admin.site.register(parts_models.PackageParameter) admin.site.register(parts_models.ComponentParameterType) admin.site.register(parts_models.ComponentType) admin.site.register(parts_models.Distributor) diff --git a/shimatta_kenkyusho/parts/migrations/0013_packageparameter.py b/shimatta_kenkyusho/parts/migrations/0013_packageparameter.py new file mode 100644 index 0000000..f11b6a3 --- /dev/null +++ b/shimatta_kenkyusho/parts/migrations/0013_packageparameter.py @@ -0,0 +1,49 @@ +# Generated by Django 5.1.3 on 2024-11-19 20:26 + +import django.db.models.deletion +import uuid +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("parts", "0012_storage_verbose_name"), + ] + + operations = [ + migrations.CreateModel( + name="PackageParameter", + fields=[ + ( + "id", + models.UUIDField( + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + unique=True, + ), + ), + ("value", models.FloatField(default=0)), + ("text_value", models.TextField(blank=True)), + ( + "package", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="parts.package" + ), + ), + ( + "parameter_type", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="parts.componentparametertype", + ), + ), + ], + options={ + "ordering": ["id"], + "unique_together": {("package", "parameter_type")}, + }, + ), + ] diff --git a/shimatta_kenkyusho/parts/models.py b/shimatta_kenkyusho/parts/models.py index ee10485..251aed5 100644 --- a/shimatta_kenkyusho/parts/models.py +++ b/shimatta_kenkyusho/parts/models.py @@ -238,24 +238,25 @@ class Component(models.Model): sum = 0 return sum - -class ComponentParameter(models.Model): +class AbstractParameter(models.Model): class Meta: - unique_together = ('component', 'parameter_type') - ordering = ['id'] + abstract = True + id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True) - component = models.ForeignKey(Component, on_delete=models.CASCADE) # A target component is required! parameter_type = models.ForeignKey(ComponentParameterType, on_delete=models.CASCADE) value = models.FloatField(default=0) text_value = models.TextField(null=False, blank=True) + def _get_object_of_param(self): + return None + def __str__(self): if self.parameter_type.parameter_type == 'F': value = self.text_value else: value = str(self.value) - return str(self.component)+ ': '+ str(self.parameter_type) + ': ' + value + return str(self._get_object_of_param())+ ': '+ str(self.parameter_type) + ': ' + value def resolved_value_as_string(self): my_type = self.parameter_type.parameter_type @@ -270,6 +271,24 @@ class ComponentParameter(models.Model): elif my_type == 'F': return self.text_value +class ComponentParameter(AbstractParameter): + class Meta: + unique_together = ('component', 'parameter_type') + ordering = ['id'] + component = models.ForeignKey(Component, on_delete=models.CASCADE) # A target component is required! + + def _get_object_of_param(self): + return self.component + +class PackageParameter(AbstractParameter): + class Meta: + unique_together = ('package', 'parameter_type') + ordering = ['id'] + package = models.ForeignKey(Package, on_delete=models.CASCADE) + + def _get_object_of_param(self): + return self.package + class Stock(models.Model): class Meta: unique_together = ('component', 'storage')