added vehicles and vehicles extra, dynamic tables for entities, dynamic dropdowns with overlay for selecting and manage data

This commit is contained in:
2026-02-10 17:32:33 +02:00
parent ed35a90cc0
commit 6a42099169
60 changed files with 4845 additions and 81 deletions
+66 -5
View File
@@ -1,13 +1,39 @@
from django.db import models
# Create your models here.
class Nomenclature(models.Model):
VEHICLE = "vehicle"
CONTAINER = "container"
APPLIES_TO_CHOICES = [
(VEHICLE, "Vehicle"),
(CONTAINER, "Container"),
]
LOOKUP = "lookup"
FIELD = "field"
KIND_CHOICES = [
(LOOKUP, "Lookup Table"),
(FIELD, "Custom Field"),
]
code = models.CharField(max_length=50, unique=True)
name = models.CharField(max_length=255)
applies_to = models.CharField(
applies_to = models.CharField(max_length=50, choices=APPLIES_TO_CHOICES)
kind = models.CharField(max_length=10, choices=KIND_CHOICES, default=LOOKUP)
display_field = models.CharField(
max_length=50,
choices=[("vehicle", "Vehicle"), ("container", "Container")]
default="name",
blank=True,
help_text="Key of the NomenclatureField to use as dropdown label (for lookup kind)",
)
sort_order = models.IntegerField(default=0)
class Meta:
ordering = ["sort_order", "code"]
def __str__(self):
return f"{self.name} ({self.code})"
class NomenclatureField(models.Model):
TEXT = "text"
@@ -23,7 +49,42 @@ class NomenclatureField(models.Model):
]
nomenclature = models.ForeignKey(
Nomenclature, on_delete=models.CASCADE
Nomenclature,
on_delete=models.CASCADE,
related_name="fields",
)
key = models.CharField(max_length=50)
field_type = models.CharField(max_length=20, choices=FIELD_TYPES)
label = models.CharField(max_length=100, blank=True)
field_type = models.CharField(max_length=20, choices=FIELD_TYPES)
required = models.BooleanField(default=False)
choices = models.JSONField(
null=True,
blank=True,
help_text='List of allowed values for choice type, e.g. ["Red","Green","Blue"]',
)
sort_order = models.IntegerField(default=0)
class Meta:
unique_together = [("nomenclature", "key")]
ordering = ["sort_order", "key"]
def __str__(self):
return f"{self.nomenclature.code}.{self.key} ({self.field_type})"
class NomenclatureEntry(models.Model):
nomenclature = models.ForeignKey(
Nomenclature,
on_delete=models.CASCADE,
related_name="entries",
)
data = models.JSONField(default=dict)
is_active = models.BooleanField(default=True)
class Meta:
verbose_name_plural = "Nomenclature entries"
ordering = ["id"]
def __str__(self):
display_key = self.nomenclature.display_field or "name"
return str(self.data.get(display_key, f"Entry #{self.pk}"))