summaryrefslogtreecommitdiff
path: root/app/figments/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/figments/models.py')
-rw-r--r--app/figments/models.py23
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
-