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