1 from django.db import models
2 from django.utils.translation import gettext_lazy as _
3 from .constants import WIKIDATA
4 from .wikidata import WikidataMixin
7 class Author(WikidataMixin, models.Model):
8 slug = models.SlugField(max_length=255, null=True, blank=True, unique=True)
9 first_name = models.CharField(max_length=255, blank=True)
10 last_name = models.CharField(max_length=255, blank=True)
12 name_de = models.CharField(max_length=255, blank=True)
13 name_lt = models.CharField(max_length=255, blank=True)
15 year_of_death = models.SmallIntegerField(null=True, blank=True)
16 status = models.PositiveSmallIntegerField(
26 notes = models.TextField(blank=True)
27 gazeta_link = models.CharField(max_length=255, blank=True)
28 culturepl_link = models.CharField(max_length=255, blank=True)
30 description = models.TextField(blank=True)
31 description_de = models.TextField(blank=True)
32 description_lt = models.TextField(blank=True)
34 priority = models.PositiveSmallIntegerField(
35 default=0, choices=[(0, _("Low")), (1, _("Medium")), (2, _("High"))]
37 collections = models.ManyToManyField("Collection", blank=True)
40 ordering = ("last_name", "first_name", "year_of_death")
43 first_name = WIKIDATA.GIVEN_NAME
44 last_name = WIKIDATA.LAST_NAME
45 year_of_death = WIKIDATA.DATE_OF_DEATH
49 return f"{self.first_name} {self.last_name}"
52 class Book(WikidataMixin, models.Model):
53 slug = models.SlugField(max_length=255, blank=True, null=True, unique=True)
54 authors = models.ManyToManyField(Author, blank=True)
55 translators = models.ManyToManyField(
57 related_name="translated_book_set",
58 related_query_name="translated_book",
61 title = models.CharField(max_length=255, blank=True)
62 language = models.CharField(max_length=255, blank=True)
63 based_on = models.ForeignKey(
64 "self", models.PROTECT, related_name="translation", null=True, blank=True
66 scans_source = models.CharField(max_length=255, blank=True)
67 text_source = models.CharField(max_length=255, blank=True)
68 notes = models.TextField(blank=True)
69 priority = models.PositiveSmallIntegerField(
70 default=0, choices=[(0, _("Low")), (1, _("Medium")), (2, _("High"))]
72 pd_year = models.IntegerField(null=True, blank=True)
73 gazeta_link = models.CharField(max_length=255, blank=True)
74 collections = models.ManyToManyField("Collection", blank=True)
80 authors = WIKIDATA.AUTHOR
81 translators = WIKIDATA.TRANSLATOR
82 title = WIKIDATA.TITLE
83 language = WIKIDATA.LANGUAGE
84 based_on = WIKIDATA.BASED_ON
89 astr = self.authors_str()
91 txt = f"{astr} – {txt}"
92 tstr = self.translators_str()
94 txt = f"{txt} (tłum. {tstr})"
97 def authors_str(self):
98 return ", ".join(str(author) for author in self.authors.all())
100 def translators_str(self):
101 return ", ".join(str(author) for author in self.translators.all())
104 class Collection(models.Model):
105 name = models.CharField(max_length=255)
106 slug = models.SlugField(max_length=255, unique=True)