diff options
author | luxagraf <sng@luxagraf.net> | 2015-11-11 21:54:21 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2015-11-11 21:54:21 -0500 |
commit | 92abffcc98404825324341d5ee654642364890bb (patch) | |
tree | aa39b2c4d85e89b452c8c72aef9803da1adeac9c /app/figments/models.py | |
parent | b588a5587c1f9a809509b77b11f4827c6c28f951 (diff) |
redo figments to work with CBV, new builder, etc. Also broke out admin
textfield widget to utils
Diffstat (limited to 'app/figments/models.py')
-rw-r--r-- | app/figments/models.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/app/figments/models.py b/app/figments/models.py index 858c6ed..e108e21 100644 --- a/app/figments/models.py +++ b/app/figments/models.py @@ -1,14 +1,18 @@ import datetime +from itertools import chain from django.db import models +from django.core.urlresolvers import reverse from django.contrib.sitemaps import Sitemap from django.contrib.syndication.views import Feed from django.db.models.signals import post_save from django.dispatch import receiver - # http://freewisdom.org/projects/python-markdown/ import markdown +from .ebook import generate_epub_file + + class Series(models.Model): title = models.CharField(max_length=200) slug = models.CharField(max_length=50) @@ -23,6 +27,7 @@ class Series(models.Model): def __str__(self): return self.title + class Figment(models.Model): title = models.CharField(max_length=200) slug = models.CharField(max_length=50) @@ -36,7 +41,7 @@ class Figment(models.Model): (1, 'Published'), ) status = models.IntegerField(choices=PUB_STATUS, default=0) - series = models.ManyToManyField(Series, blank=True) + series = models.ManyToManyField(Series, related_name="series", blank=True) TEMPLATES = ( (0, 'default'), ) @@ -48,10 +53,10 @@ class Figment(models.Model): def __str__(self): return self.title - + def get_absolute_url(self): - return "/figments/%s" % self.slug - + return reverse("figments:detail", kwargs={"slug": self.slug}) + def get_series(self): return "\n".join([s.title for s in self.series.all()]) @@ -76,8 +81,6 @@ class Figment(models.Model): super(Figment, self).save() -from .ebook import generate_epub_file - @receiver(post_save, sender=Figment) def post_save_events(sender, instance, **kwargs): if instance.body_markdown != instance._loaded_values['body_markdown']: @@ -97,9 +100,6 @@ class LatestFull(Feed): return Figment.objects.filter(status__exact=1).order_by('-pub_date')[:10] - -from itertools import chain - class FigmentSitemap(Sitemap): changefreq = "never" priority = 0.7 @@ -107,7 +107,6 @@ class FigmentSitemap(Sitemap): def items(self): return list(chain(Figment.objects.filter(status__exact=1), Series.objects.all())) - + def lastmod(self, obj): return obj.pub_date - |