]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/blog/models.py
Make posted comments give a better message
[sommitrealweird.git] / sommitrealweird / blog / models.py
1 from django.contrib.comments.moderation import CommentModerator, moderator
2 from django.db import models
3 from django.conf import settings
4 from django.contrib import admin
5
6 FORMAT_CHOICES = (
7     ('rst', 'reStructuredText'),
8     ('html', 'HTML'),
9 )
10
11 class BlogEntry(models.Model):
12     title = models.CharField(max_length=150)
13     islive = models.BooleanField()
14     sections = models.ManyToManyField('BlogSection')
15     format = models.CharField(max_length=10, choices=FORMAT_CHOICES)
16     slug = models.SlugField()
17     publish_date = models.DateTimeField()
18     content = models.TextField()
19
20     def __str__(self):
21         return self.__unicode__()
22
23     def __unicode__(self):
24         return u'%s - %s' %(self.publish_date.strftime('%Y-%m-%d %H:%M'), self.title)
25
26     def get_absolute_url(self):
27         return u'%s%04d/%02d/%02d/%s/' %(settings.BLOG_ROOT, self.publish_date.year, self.publish_date.month, self.publish_date.day, self.slug)
28
29     class Meta:
30         ordering = ['-publish_date']
31
32 class BlogEntryCommentModerator(CommentModerator):
33     email_notification = True
34
35     def moderate(self, comment, content_object, request):
36         return True
37
38 moderator.register(BlogEntry, BlogEntryCommentModerator)
39
40 class BlogSection(models.Model):
41     title = models.CharField(max_length=150)
42     slug = models.SlugField()
43
44     def __str__(self):
45         return self.__unicode__()
46
47     def __unicode__(self):
48         return u'%s' %(self.title,)
49
50     def get_absolute_url(self):
51         return u'%ssection/%s/' %(settings.BLOG_ROOT, self.slug)