]> gitweb.fperrin.net Git - djsite.git/blob - quotes/models.py
83bf62b49696e90ce8b758e378d74ebd6a431508
[djsite.git] / quotes / models.py
1 from django.db import models
2 from django.urls import reverse
3
4 from localmodels import HTMLField
5
6 # Create your models here.
7 class BaseTag(models.Model):
8     tag = models.CharField(max_length=100, unique=True)
9
10     def __unicode__(self):
11         return self.tag
12
13     class Meta(object):
14         abstract = True
15
16 class AuthorTag(BaseTag): pass
17 class WorkTag(BaseTag): pass
18 class QuoteTag(BaseTag):
19     def get_absolute_url(self):
20         return reverse('quotes:tags', args=[str(self.id)])
21
22 class CommonData(models.Model):
23     creation_date = models.DateTimeField(auto_now_add=True)
24     last_modification = models.DateTimeField(auto_now=True)
25
26     notes = HTMLField(blank=True, help_text= \
27                       "Notes about the entry; may be left blank. Displayed \
28                       on the public pages")
29     pvt_notes = HTMLField(blank=True, help_text= \
30                           "Notes about the entry; not displayed on \
31                           the public interface")
32
33     class Meta(object):
34         abstract = True
35
36 class Author(CommonData):
37     name = models.CharField(max_length=100,
38                             help_text="Name of the author",
39                             unique=True)
40
41     tags = models.ManyToManyField(AuthorTag, blank=True,
42                                   help_text='Not implemented yet')
43
44     birth_date = models.DateField(blank=True, null=True,
45                                   help_text="Date of birth")
46     death_date = models.DateField(blank=True, null=True,
47                                   help_text="Date of death (leave blank \
48                                   if still alive!)")
49
50     def __str__(self):
51         return self.name
52
53     def get_absolute_url(self):
54         return reverse('quotes:author', args=[str(self.id)])
55
56 # class DatePrecision(models.CharField):
57 #     DAY = "D"
58 #     MONTH = "M"
59 #     YEAR = "Y"
60 #     DECADE = "X"
61 #     CENTURY = "C"
62 #     UNKNOWN = "?"
63 #     PRECISION_CHOICES = [
64 #         (DAY, "Day"),
65 #         (MONTH, "Month"),
66 #         (YEAR, "Year"),
67 #         (DECADE, "Decade"),
68 #         (CENTURY, "Century"),
69 #         (UNKNOWN, "Unknown"),
70 #     ]
71 #     def __init__(self, **kwargs):
72 #         models.CharField(max_length=1, choices=self.PRECISION_CHOICES,
73 #                          default=self.DAY, **kwargs)
74
75 class Work(CommonData):
76     name = models.CharField(max_length=100,
77                             help_text="Name of the context for the quote \
78                             (title of the work or speech it appears in)",
79                             unique=True)
80     author = models.ForeignKey(Author)
81     date = models.DateField(blank=True, null=True,
82                             help_text="Date of the quote")
83     tags = models.ManyToManyField(WorkTag, blank=True,
84                                   help_text='Not implemented yet')
85
86     def __str__(self):
87         return "%s: %s (%s)" % (self.author.name, self.name, self.date)
88
89     def get_absolute_url(self):
90         return reverse('quotes:work', args=[str(self.id)])
91
92 class Quote(CommonData):
93     text = HTMLField()
94     tags = models.ManyToManyField(QuoteTag, blank=True)
95     work = models.ForeignKey(Work)
96
97     def __str__(self):
98         return self.work.author.name + ": " + self.text
99
100     def get_absolute_url(self):
101         return reverse('quotes:onequote', args=[str(self.id)])