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