]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/blog/models.py
Clean up photos so that it does 404s
[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(default=False)
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         if request.user.is_authenticated():
37             return False
38         else:
39             return True
40
41 moderator.register(BlogEntry, BlogEntryCommentModerator)
42
43 class BlogSection(models.Model):
44     title = models.CharField(max_length=150)
45     slug = models.SlugField()
46
47     def __str__(self):
48         return self.__unicode__()
49
50     def __unicode__(self):
51         return u'%s' %(self.title,)
52
53     def get_absolute_url(self):
54         return u'%ssection/%s/' %(settings.BLOG_ROOT, self.slug)