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")
33 nb_display = models.BigIntegerField(default=0)
34 def incr_display(self):
35 self.nb_display = models.F('nb_display') + 1
41 class Author(CommonData):
42 name = models.CharField(max_length=100,
43 help_text="Name of the author",
46 tags = models.ManyToManyField(AuthorTag, blank=True,
47 help_text='Not implemented yet')
49 birth_date = models.DateField(blank=True, null=True,
50 help_text="Date of birth")
51 death_date = models.DateField(blank=True, null=True,
52 help_text="Date of death (leave blank \
58 def get_absolute_url(self):
59 return reverse('quotes:author', args=[str(self.id)])
61 # class DatePrecision(models.CharField):
68 # PRECISION_CHOICES = [
73 # (CENTURY, "Century"),
74 # (UNKNOWN, "Unknown"),
76 # def __init__(self, **kwargs):
77 # models.CharField(max_length=1, choices=self.PRECISION_CHOICES,
78 # default=self.DAY, **kwargs)
80 class Work(CommonData):
81 name = models.CharField(max_length=100,
82 help_text="Name of the context for the quote \
83 (title of the work or speech it appears in)",
85 author = models.ForeignKey(Author)
86 date = models.DateField(blank=True, null=True,
87 help_text="Date of the quote")
88 tags = models.ManyToManyField(WorkTag, blank=True,
89 help_text='Not implemented yet')
92 return "%s: %s (%s)" % (self.author.name, self.name, self.date)
94 def get_absolute_url(self):
95 return reverse('quotes:work', args=[str(self.id)])
97 class Quote(CommonData):
99 tags = models.ManyToManyField(QuoteTag, blank=True)
100 work = models.ForeignKey(Work)
103 return self.work.author.name + ": " + self.text
105 def get_absolute_url(self):
106 return reverse('quotes:onequote', args=[str(self.id)])