models.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from django.db import models
  2. from django.utils.html import mark_safe
  3. from colorfield.fields import ColorField
  4. class Group(models.Model):
  5. name = models.CharField(max_length=255)
  6. color = ColorField(default='#87bb37')
  7. def __str__(self) -> str:
  8. return str(self.name)
  9. class Meta:
  10. verbose_name = "Gruppe"
  11. verbose_name_plural = "Gruppen"
  12. class Person(models.Model):
  13. name = models.CharField(max_length=255)
  14. parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.PROTECT, related_name='parent_map', verbose_name="Eltern")
  15. partners = models.ManyToManyField('self', blank=True, verbose_name="Partner")
  16. birth_date = models.DateField(null=True, blank=True, verbose_name="Geburtsdatum")
  17. birth_town = models.CharField(max_length=255, null=True, blank=True, verbose_name="Geburtsort")
  18. death_date = models.DateField(null=True, blank=True, verbose_name="Todesdatum")
  19. death_town = models.CharField(max_length=255, null=True, blank=True, verbose_name="Todesort")
  20. comment = models.TextField(null=True, blank=True, verbose_name="Kommentar")
  21. image = models.ImageField(upload_to='stammbaum/images', null=True, blank=True, verbose_name="Bild")
  22. color = ColorField(null=True, blank=True, verbose_name="Farbe")
  23. group = models.ForeignKey(Group, on_delete=models.PROTECT, verbose_name="Gruppe")
  24. def image_tag(self):
  25. if self.image:
  26. return mark_safe(f'<img src="/stammbaum/person/{self.id}/thumb" />')
  27. image_tag.short_description = 'Vorschau'
  28. def __str__(self) -> str:
  29. tmp = self.name
  30. #if self.parent:
  31. # tmp = F"{self.parent.name} -> {tmp}"
  32. if self.birth_date:
  33. tmp += " *" + self.birth_date.strftime("%d.%m.%Y")
  34. return tmp
  35. class Meta:
  36. verbose_name = "Person"
  37. verbose_name_plural = "Personen"
  38. permissions = [
  39. (
  40. "view",
  41. "Can view Stammbaum"
  42. ),
  43. (
  44. "upload_image",
  45. "Can upload images"
  46. )
  47. ]