]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/blog/models.py
Stop ReST from dropping the primary title if it's the first title in the document.
[sommitrealweird.git] / sommitrealweird / blog / models.py
1 from django.db import models
2 from django.conf import settings
3 from django.contrib import admin
4
5 FORMAT_CHOICES = (
6     ('rst', 'reStructuredText'),
7     ('html', 'HTML'),
8 )
9
10 class BlogEntry(models.Model):
11     title = models.CharField(max_length=150)
12     islive = models.BooleanField()
13     sections = models.ManyToManyField('BlogSection')
14     format = models.CharField(max_length=10, choices=FORMAT_CHOICES)
15     slug = models.SlugField()
16     publish_date = models.DateTimeField()
17     content = models.TextField()
18
19     def __str__(self):
20         return self.__unicode__()
21
22     def __unicode__(self):
23         return u'%s - %s' %(self.publish_date.strftime('%Y-%m-%d %H:%M'), self.title)
24
25     def get_absolute_url(self):
26         return u'%s%04d/%02d/%02d/%s/' %(settings.BLOG_ROOT, self.publish_date.year, self.publish_date.month, self.publish_date.day, self.slug)
27
28     class Meta:
29         ordering = ['-publish_date']
30
31 class BlogSection(models.Model):
32     title = models.CharField(max_length=150)
33     slug = models.SlugField()
34
35     def __str__(self):
36         return self.__unicode__()
37
38     def __unicode__(self):
39         return u'%s' %(self.title,)
40
41     def get_absolute_url(self):
42         return u'%ssection/%s/' %(settings.BLOG_ROOT, self.slug)