from django.db import models from django.utils.html import mark_safe from colorfield.fields import ColorField class Group(models.Model): name = models.CharField(max_length=255) color = ColorField(default='#87bb37') def __str__(self) -> str: return str(self.name) class Meta: verbose_name = "Gruppe" verbose_name_plural = "Gruppen" class Person(models.Model): name = models.CharField(max_length=255) parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.PROTECT, related_name='parent_map', verbose_name="Eltern") partners = models.ManyToManyField('self', blank=True, verbose_name="Partner") birth_date = models.DateField(null=True, blank=True, verbose_name="Geburtsdatum") birth_town = models.CharField(max_length=255, null=True, blank=True, verbose_name="Geburtsort") death_date = models.DateField(null=True, blank=True, verbose_name="Todesdatum") death_town = models.CharField(max_length=255, null=True, blank=True, verbose_name="Todesort") comment = models.TextField(null=True, blank=True, verbose_name="Kommentar") image = models.ImageField(upload_to='stammbaum/images', null=True, blank=True, verbose_name="Bild") color = ColorField(null=True, blank=True, verbose_name="Farbe") group = models.ForeignKey(Group, on_delete=models.PROTECT, verbose_name="Gruppe") def image_tag(self): if self.image: return mark_safe(f'') image_tag.short_description = 'Vorschau' def __str__(self) -> str: tmp = self.name #if self.parent: # tmp = F"{self.parent.name} -> {tmp}" if self.birth_date: tmp += " *" + self.birth_date.strftime("%d.%m.%Y") return tmp class Meta: verbose_name = "Person" verbose_name_plural = "Personen" permissions = [ ( "view", "Can view Stammbaum" ), ( "upload_image", "Can upload images" ) ]