teilchensammler/collector/models.py

24 lines
729 B
Python
Raw Permalink Normal View History

from django.db import models
from django_extensions.db.models import ModificationDateTimeField
class Teil(models.Model):
name = models.TextField("Name of the part", null=False, blank=False)
modified = ModificationDateTimeField("last changed")
class Meta:
constraints = [
models.UniqueConstraint(fields=["name"], name="unique_names"),
]
indexes = [
models.Index(fields=["modified"], name="idx_modified"),
]
2025-03-12 22:56:09 +01:00
verbose_name = "Teil"
verbose_name_plural = "Teile"
ordering = ["-modified"]
2025-03-12 22:56:09 +01:00
def __str__(self) -> str:
modified = self.modified.isoformat(timespec="seconds")
return f"{self.name} (last change: {modified})"