From 9ccb8068a1e46fca83c7cc948cb66f17f5d570d2 Mon Sep 17 00:00:00 2001 From: Joseph Spiros Date: Wed, 30 Jun 2010 07:44:35 -0400 Subject: [PATCH] Added uniqueness constraints to Tag, NewsletterArticle, and NewsletterIssue, and added ordering to NewsletterArticle and NewsletterIssue. --- contrib/penfield/models.py | 8 ++++++++ models/base.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/contrib/penfield/models.py b/contrib/penfield/models.py index 3456c91..371ea57 100644 --- a/contrib/penfield/models.py +++ b/contrib/penfield/models.py @@ -154,6 +154,10 @@ class NewsletterArticle(Entity, Titled): date = models.DateTimeField(default=datetime.now) lede = models.TextField(null=True, blank=True) full_text = models.TextField() + + class Meta: + ordering = ['-date'] + unique_together = (('newsletter', 'slug'),) register_value_model(NewsletterArticle) @@ -163,6 +167,10 @@ class NewsletterIssue(Entity, Titled): newsletter = models.ForeignKey(Newsletter, related_name='issues') number = models.PositiveIntegerField() articles = models.ManyToManyField(NewsletterArticle) + + class Meta: + ordering = ['-number'] + unique_together = (('newsletter', 'number'),) class NewsletterView(MultiView): diff --git a/models/base.py b/models/base.py index 9434825..700b1e7 100644 --- a/models/base.py +++ b/models/base.py @@ -9,7 +9,7 @@ from UserDict import DictMixin class Tag(models.Model): name = models.CharField(max_length=250) - slug = models.SlugField() + slug = models.SlugField(unique=True) def __unicode__(self): return self.name -- 2.20.1