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 \
55 class Meta(CommonData.Meta):
58 def __unicode__(self):
61 def get_absolute_url(self):
62 return reverse('quotes:author', args=[str(self.id)])
64 # class DatePrecision(models.CharField):
71 # PRECISION_CHOICES = [
76 # (CENTURY, "Century"),
77 # (UNKNOWN, "Unknown"),
79 # def __init__(self, **kwargs):
80 # models.CharField(max_length=1, choices=self.PRECISION_CHOICES,
81 # default=self.DAY, **kwargs)
83 class Work(CommonData):
84 name = models.CharField(max_length=100,
85 help_text="Name of the context for the quote \
86 (title of the work or speech it appears in)",
88 author = models.ForeignKey(Author)
89 date = models.DateField(blank=True, null=True,
90 help_text="Date of the quote")
91 tags = models.ManyToManyField(WorkTag, blank=True,
92 help_text='Not implemented yet')
94 def __unicode__(self):
95 return "%s (%s)" % (self.name, self.author.name)
97 def get_absolute_url(self):
98 return reverse('quotes:work', args=[str(self.id)])
100 class Meta(CommonData.Meta):
103 class Quote(CommonData):
105 tags = models.ManyToManyField(QuoteTag, blank=True)
106 work = models.ForeignKey(Work)
108 def __unicode__(self):
109 return self.work.author.name + ": " + self.text
111 def get_absolute_url(self):
112 return reverse('quotes:onequote', args=[str(self.id)])
114 class Meta(CommonData.Meta):