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(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)
11 year_of_death = models.SmallIntegerField(null=True, blank=True)
12 status = models.PositiveSmallIntegerField(
22 notes = models.TextField(blank=True)
23 gazeta_link = models.CharField(max_length=255, blank=True)
24 culturepl_link = models.CharField(max_length=255, blank=True)
25 description = models.TextField(blank=True)
26 priority = models.PositiveSmallIntegerField(
27 default=0, choices=[(0, _("Low")), (1, _("Medium")), (2, _("High"))]
29 collections = models.ManyToManyField('Collection', blank=True)
32 ordering = ('last_name', 'first_name', 'year_of_death')
35 first_name = WIKIDATA.GIVEN_NAME
36 last_name = WIKIDATA.LAST_NAME
37 year_of_death = WIKIDATA.DATE_OF_DEATH
41 return f"{self.first_name} {self.last_name}"
44 class Book(WikidataMixin, models.Model):
45 slug = models.SlugField(max_length=255, blank=True, null=True, unique=True)
46 authors = models.ManyToManyField(Author, blank=True)
47 translators = models.ManyToManyField(
49 related_name="translated_book_set",
50 related_query_name="translated_book",
53 title = models.CharField(max_length=255, blank=True)
54 language = models.CharField(max_length=255, blank=True)
55 based_on = models.ForeignKey(
56 "self", models.PROTECT, related_name="translation", null=True, blank=True
58 scans_source = models.CharField(max_length=255, blank=True)
59 text_source = models.CharField(max_length=255, blank=True)
60 notes = models.TextField(blank=True)
61 priority = models.PositiveSmallIntegerField(
62 default=0, choices=[(0, _("Low")), (1, _("Medium")), (2, _("High"))]
64 pd_year = models.IntegerField(null=True, blank=True)
65 collections = models.ManyToManyField('Collection', blank=True)
71 authors = WIKIDATA.AUTHOR
72 translators = WIKIDATA.TRANSLATOR
73 title = WIKIDATA.TITLE
74 language = WIKIDATA.LANGUAGE
75 based_on = WIKIDATA.BASED_ON
80 astr = self.authors_str()
82 txt = f'{astr} – {txt}'
83 tstr = self.translators_str()
85 txt = f'{txt} (tłum. {tstr})'
88 def authors_str(self):
89 return ', '.join(str(author) for author in self.authors.all())
91 def translators_str(self):
92 return ', '.join(str(author) for author in self.translators.all())
95 class Collection(models.Model):
96 name = models.CharField(max_length=255)
97 slug = models.SlugField(max_length=255, unique=True)