1 from django.db import models
2 from django.urls import reverse
4 from localmodels import HTMLField
6 # Create your models here.
7 class BaseTag(models.Model):
8 tag = models.CharField(max_length=100, unique=True)
10 def __unicode__(self):
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)])
22 class CommonData(models.Model):
23 creation_date = models.DateTimeField(auto_now_add=True)
24 last_modification = models.DateTimeField(auto_now=True)
26 notes = HTMLField(blank=True, help_text= \
27 "Notes about the entry; may be left blank. Displayed \
29 pvt_notes = HTMLField(blank=True, help_text= \
30 "Notes about the entry; not displayed on \
31 the public interface")
36 class Author(CommonData):
37 name = models.CharField(max_length=100,
38 help_text="Name of the author",
41 tags = models.ManyToManyField(AuthorTag, blank=True,
42 help_text='Not implemented yet')
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 \
53 def get_absolute_url(self):
54 return reverse('quotes:author', args=[str(self.id)])
56 # class DatePrecision(models.CharField):
63 # PRECISION_CHOICES = [
68 # (CENTURY, "Century"),
69 # (UNKNOWN, "Unknown"),
71 # def __init__(self, **kwargs):
72 # models.CharField(max_length=1, choices=self.PRECISION_CHOICES,
73 # default=self.DAY, **kwargs)
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)",
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')
87 return "%s: %s (%s)" % (self.author.name, self.name, self.date)
89 def get_absolute_url(self):
90 return reverse('quotes:work', args=[str(self.id)])
92 class Quote(CommonData):
94 tags = models.ManyToManyField(QuoteTag, blank=True)
95 work = models.ForeignKey(Work)
98 return self.work.author.name + ": " + self.text
100 def get_absolute_url(self):
101 return reverse('quotes:onequote', args=[str(self.id)])