X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=quotes%2Fmodels.py;h=34695dfd9fbdb4af7852b5774d4c6ddb4ac6e7f1;hb=8e7c1ea13e2ab23eafb24ba2106b0dde9085f9b4;hp=cdae648e21960c540bc2dbab1b9b8334ffdf9344;hpb=b22937332fc5fa45d2beb8fb0bf9495df7efa80c;p=djsite.git diff --git a/quotes/models.py b/quotes/models.py index cdae648..34695df 100644 --- a/quotes/models.py +++ b/quotes/models.py @@ -1,22 +1,50 @@ from django.db import models -from tinymce import models as tinymce_models +from django.urls import reverse + +from localmodels import HTMLField # Create your models here. -class Tag(models.Model): - tag = models.CharField(max_length=100) +class BaseTag(models.Model): + tag = models.CharField(max_length=100, unique=True) + def __unicode__(self): return self.tag -class Author(models.Model): + class Meta(object): + abstract = True + +class AuthorTag(BaseTag): pass +class WorkTag(BaseTag): pass +class QuoteTag(BaseTag): + def get_absolute_url(self): + return reverse('quotes:tags', args=[str(self.id)]) + +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") + + nb_display = models.BigIntegerField(default=0) + def incr_display(self): + self.nb_display = models.F('nb_display') + 1 + self.save() + + class Meta(object): + abstract = True + +class Author(CommonData): name = models.CharField(max_length=100, - help_text="Name of the author") - notes = tinymce_models.HTMLField(blank=True, help_text= \ - "Notes about the author; may be left blank. Will \ - not be HTML-escaped.",) - pvt_notes = models.TextField(blank=True, help_text= \ - "Notes about the author; not displayed on \ - the public interface",) - tags = models.ManyToManyField(Tag, blank=True) + help_text="Name of the author", + unique=True) + + tags = models.ManyToManyField(AuthorTag, blank=True, + help_text='Not implemented yet') birth_date = models.DateField(blank=True, null=True, help_text="Date of birth") @@ -24,9 +52,15 @@ class Author(models.Model): help_text="Date of death (leave blank \ if still alive!)") + class Meta(CommonData.Meta): + ordering = ['name'] + def __unicode__(self): return self.name + def get_absolute_url(self): + return reverse('quotes:author', args=[str(self.id)]) + # class DatePrecision(models.CharField): # DAY = "D" # MONTH = "M" @@ -46,36 +80,37 @@ class Author(models.Model): # models.CharField(max_length=1, choices=self.PRECISION_CHOICES, # default=self.DAY, **kwargs) -class Work(models.Model): +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)") + (title of the work or speech it appears in)", + unique=True) author = models.ForeignKey(Author) date = models.DateField(blank=True, null=True, help_text="Date of the quote") - tags = models.ManyToManyField(Tag, blank=True) - - notes = models.TextField(blank=True, help_text= \ - "Notes about the work; may be left blank. Will \ - not be HTML-escaped. XXX: offer a WYSIWYG editor") - pvt_notes = models.TextField(blank=True, help_text= \ - "Notes about the work; not displayed on \ - the public interface") + tags = models.ManyToManyField(WorkTag, blank=True, + help_text='Not implemented yet') - def __str__(self): + def __unicode__(self): return "%s: %s (%s)" % (self.author.name, self.name, self.date) -class Quote(models.Model): - text = models.TextField() - tags = models.ManyToManyField(Tag, blank=True) - work = models.ForeignKey(Work) + def get_absolute_url(self): + return reverse('quotes:work', args=[str(self.id)]) - notes = models.TextField(blank=True, help_text= \ - "Notes about the quote; may be left blank. Will \ - not be HTML-escaped. XXX: offer a WYSIWYG editor") - pvt_notes = models.TextField(blank=True, help_text= \ - "Notes about the quote; not displayed on \ - the public interface") + class Meta(CommonData.Meta): + ordering = ['name'] + +class Quote(CommonData): + text = HTMLField() + tags = models.ManyToManyField(QuoteTag, blank=True) + work = models.ForeignKey(Work) def __unicode__(self): return self.work.author.name + ": " + self.text + + def get_absolute_url(self): + return reverse('quotes:onequote', args=[str(self.id)]) + + class Meta(CommonData.Meta): + ordering = ['-pk'] +