X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=quotes%2Fmodels.py;h=0fa66afd0ed91e8e076bd7d674c068246ef09b46;hb=1beb1e7de4e076707eedf1be7386b238f19aeb60;hp=71a836239075aa6e6e4ecb700e9c42c95c022d91;hpb=e63e884391c4ac2c3af8ff72919a196f7bf9d83f;p=djsite.git diff --git a/quotes/models.py b/quotes/models.py index 71a8362..0fa66af 100644 --- a/quotes/models.py +++ b/quotes/models.py @@ -1,3 +1,81 @@ from django.db import models +from localmodels import HTMLField # Create your models here. +class Tag(models.Model): + tag = models.CharField(max_length=100) + def __unicode__(self): + return self.tag + +class Author(models.Model): + name = models.CharField(max_length=100, + help_text="Name of the author") + notes = HTMLField(blank=True, help_text= \ + "Notes about the author; may be left blank. Will \ + not be HTML-escaped.",) + pvt_notes = HTMLField(blank=True, help_text= \ + "Notes about the author; not displayed on \ + the public interface",) + tags = models.ManyToManyField(Tag, blank=True) + + 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(models.Model): + name = models.CharField(max_length=100, + help_text="Name of the context for the quote \ + (title of the work or speech it appears in)") + author = models.ForeignKey(Author) + date = models.DateField(blank=True, null=True, + help_text="Date of the quote") + tags = models.ManyToManyField(Tag, blank=True) + + notes = HTMLField(blank=True, help_text= \ + "Notes about the work; may be left blank. Will \ + not be HTML-escaped. XXX: offer a WYSIWYG editor") + pvt_notes = HTMLField(blank=True, help_text= \ + "Notes about the work; not displayed on \ + the public interface") + + def __str__(self): + return "%s: %s (%s)" % (self.author.name, self.name, self.date) + +class Quote(models.Model): + text = HTMLField() + tags = models.ManyToManyField(Tag, blank=True) + work = models.ForeignKey(Work) + + notes = HTMLField(blank=True, help_text= \ + "Notes about the quote; may be left blank. Will \ + not be HTML-escaped. XXX: offer a WYSIWYG editor") + pvt_notes = HTMLField(blank=True, help_text= \ + "Notes about the quote; not displayed on \ + the public interface") + + def __str__(self): + return self.work.author.name + ": " + self.text