Add basic blogging support
[sommitrealweird.git] / sommitrealweird / blog / models.py
diff --git a/sommitrealweird/blog/models.py b/sommitrealweird/blog/models.py
new file mode 100644 (file)
index 0000000..6b0d254
--- /dev/null
@@ -0,0 +1,44 @@
+from django.db import models
+from django.conf import settings
+
+FORMAT_CHOICES = (
+    ('rst', 'reStructuredText'),
+    ('html', 'HTML'),
+)
+
+class BlogEntry(models.Model):
+    title = models.CharField(maxlength=150)
+    islive = models.BooleanField()
+    sections = models.ManyToManyField('BlogSection')
+    format = models.CharField(maxlength=10, choices=FORMAT_CHOICES)
+    slug = models.SlugField(prepopulate_from=("title",))
+    publish_date = models.DateTimeField()
+    content = models.TextField()
+
+    def __str__(self):
+        return self.__unicode__()
+
+    def __unicode__(self):
+        return u'%s - %s' %(self.publish_date.strftime('%Y-%m-%d %H:%M'), self.title)
+
+    def get_absolute_url(self):
+        return u'%s%04d/%02d/%02d/%s/' %(settings.BLOG_ROOT, self.publish_date.year, self.publish_date.month, self.publish_date.day, self.slug)
+
+    class Admin:
+        pass
+
+class BlogSection(models.Model):
+    title = models.CharField(maxlength=150)
+    slug = models.SlugField(prepopulate_from=("title",))
+
+    def __str__(self):
+        return self.__unicode__()
+
+    def __unicode__(self):
+        return u'%s' %(self.title,)
+
+    def get_absolute_url(self):
+        return u'%ssection/%s/' %(settings.BLOG_ROOT, self.slug)
+
+    class Admin:
+        pass