add default sort ordering for blog entries
[sommitrealweird.git] / sommitrealweird / blog / models.py
1 from django.db import models
2 from django.conf import settings
3
4 FORMAT_CHOICES = (
5     ('rst', 'reStructuredText'),
6     ('html', 'HTML'),
7 )
8
9 class BlogEntry(models.Model):
10     title = models.CharField(maxlength=150)
11     islive = models.BooleanField()
12     sections = models.ManyToManyField('BlogSection')
13     format = models.CharField(maxlength=10, choices=FORMAT_CHOICES)
14     slug = models.SlugField(prepopulate_from=("title",))
15     publish_date = models.DateTimeField()
16     content = models.TextField()
17
18     def __str__(self):
19         return self.__unicode__()
20
21     def __unicode__(self):
22         return u'%s - %s' %(self.publish_date.strftime('%Y-%m-%d %H:%M'), self.title)
23
24     def get_absolute_url(self):
25         return u'%s%04d/%02d/%02d/%s/' %(settings.BLOG_ROOT, self.publish_date.year, self.publish_date.month, self.publish_date.day, self.slug)
26
27     class Meta:
28         ordering = ['-publish_date']
29
30     class Admin:
31         pass
32
33 class BlogSection(models.Model):
34     title = models.CharField(maxlength=150)
35     slug = models.SlugField(prepopulate_from=("title",))
36
37     def __str__(self):
38         return self.__unicode__()
39
40     def __unicode__(self):
41         return u'%s' %(self.title,)
42
43     def get_absolute_url(self):
44         return u'%ssection/%s/' %(settings.BLOG_ROOT, self.slug)
45
46     class Admin:
47         pass