X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=quotes%2Fmodels.py;h=e23fde52a0a1475496212a1bc421534ce5296028;hb=0b43566359216637a28247d7f9ab4121931843ed;hp=9791aa0b093b00eb924a76d8b0b52e1ac98574b2;hpb=45be55604156dc0064aa32ea508df0d90ac5a17a;p=djsite.git diff --git a/quotes/models.py b/quotes/models.py index 9791aa0..e23fde5 100644 --- a/quotes/models.py +++ b/quotes/models.py @@ -1,27 +1,88 @@ from django.db import models +from localmodels import HTMLField # Create your models here. - -class Author(models.Model): - name = models.CharField(max_length=100) +class BaseTag(models.Model): + tag = models.CharField(max_length=100, unique=True) def __unicode__(self): - return self.name + return self.tag -class Tag(models.Model): - tag = models.CharField(max_length=100) + class Meta(object): + abstract = True - def __unicode__(self): - return self.tag +class AuthorTag(BaseTag): pass +class WorkTag(BaseTag): pass +class QuoteTag(BaseTag): pass + +class CommonData(models.Model): + creation_date = models.DateTimeField(auto_now_add=True) + last_modification = models.DateTimeField(auto_now=True) + + notes = HTMLField(blank=True, help_text= \ + "Notes about the entry; may be left blank. Displayed \ + on the public pages") + pvt_notes = HTMLField(blank=True, help_text= \ + "Notes about the entry; not displayed on \ + the public interface") + + class Meta(object): + abstract = True - class Meta: - ordering = ("tag", ) +class Author(CommonData): + name = models.CharField(max_length=100, + help_text="Name of the author", + unique=True) -class Quote(models.Model): - text = models.TextField() + tags = models.ManyToManyField(AuthorTag, blank=True, + help_text='Not implemented yet') + + birth_date = models.DateField(blank=True, null=True, + help_text="Date of birth") + death_date = models.DateField(blank=True, null=True, + help_text="Date of death (leave blank \ + if still alive!)") + + def __str__(self): + return self.name + +# class DatePrecision(models.CharField): +# DAY = "D" +# MONTH = "M" +# YEAR = "Y" +# DECADE = "X" +# CENTURY = "C" +# UNKNOWN = "?" +# PRECISION_CHOICES = [ +# (DAY, "Day"), +# (MONTH, "Month"), +# (YEAR, "Year"), +# (DECADE, "Decade"), +# (CENTURY, "Century"), +# (UNKNOWN, "Unknown"), +# ] +# def __init__(self, **kwargs): +# models.CharField(max_length=1, choices=self.PRECISION_CHOICES, +# default=self.DAY, **kwargs) + +class Work(CommonData): + name = models.CharField(max_length=100, + help_text="Name of the context for the quote \ + (title of the work or speech it appears in)", + unique=True) author = models.ForeignKey(Author) - tags = models.ManyToManyField(Tag, blank=True) + date = models.DateField(blank=True, null=True, + help_text="Date of the quote") + tags = models.ManyToManyField(WorkTag, blank=True, + help_text='Not implemented yet') - def __unicode__(self): - return self.author.name + ": " + self.text + def __str__(self): + return "%s: %s (%s)" % (self.author.name, self.name, self.date) + +class Quote(CommonData): + text = HTMLField() + tags = models.ManyToManyField(QuoteTag, blank=True) + work = models.ForeignKey(Work) + def __str__(self): + return self.work.author.name + ": " + self.text