]> gitweb.fperrin.net Git - djsite.git/blobdiff - quotes/models.py
Better implement tags, with separate namespaces
[djsite.git] / quotes / models.py
index 0fa66afd0ed91e8e076bd7d674c068246ef09b46..e23fde52a0a1475496212a1bc421534ce5296028 100644 (file)
@@ -2,21 +2,40 @@ from django.db import models
 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):
-    name = models.CharField(max_length=100,
-                            help_text="Name of the author")
+    class Meta(object):
+        abstract = True
+
+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 author; may be left blank. Will \
-                      not be HTML-escaped.",)
+                      "Notes about the entry; may be left blank. Displayed \
+                      on the public pages")
     pvt_notes = HTMLField(blank=True, help_text= \
-                          "Notes about the author; not displayed on \
-                          the public interface",)
-    tags = models.ManyToManyField(Tag, blank=True)
+                          "Notes about the entry; not displayed on \
+                          the public interface")
+
+    class Meta(object):
+        abstract = True
+
+class Author(CommonData):
+    name = models.CharField(max_length=100,
+                            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")
@@ -46,36 +65,24 @@ 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 = 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")
+    tags = models.ManyToManyField(WorkTag, blank=True,
+                                  help_text='Not implemented yet')
 
     def __str__(self):
         return "%s: %s (%s)" % (self.author.name, self.name, self.date)
 
-class Quote(models.Model):
+class Quote(CommonData):
     text = HTMLField()
-    tags = models.ManyToManyField(Tag, blank=True)
+    tags = models.ManyToManyField(QuoteTag, 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