~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to news/models.py

  • Committer: Holger Rapp
  • Date: 2009-02-21 18:24:02 UTC
  • Revision ID: sirver@kallisto.local-20090221182402-k3tuf5c4gjwslbjf
Main Page contains now the same informations as before

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.db import models
 
2
from django.utils.translation import ugettext_lazy as _
 
3
from django.db.models import permalink
 
4
from django.contrib.auth.models import User
 
5
from tagging.fields import TagField
 
6
from widelands.news.managers import PublicManager
 
7
 
 
8
import tagging
 
9
 
 
10
 
 
11
class Category(models.Model):
 
12
    """Category model."""
 
13
    title       = models.CharField(_('title'), max_length=100)
 
14
    slug        = models.SlugField(_('slug'), unique=True)
 
15
 
 
16
    class Meta:
 
17
        verbose_name = _('category')
 
18
        verbose_name_plural = _('categories')
 
19
        db_table = 'news_categories'
 
20
        ordering = ('title',)
 
21
 
 
22
    class Admin:
 
23
        pass
 
24
 
 
25
    def __unicode__(self):
 
26
        return u'%s' % self.title
 
27
 
 
28
    @permalink
 
29
    def get_absolute_url(self):
 
30
        return ('news_category_detail', None, {'slug': self.slug})
 
31
 
 
32
 
 
33
class Post(models.Model):
 
34
    """Post model."""
 
35
    STATUS_CHOICES = (
 
36
        (1, _('Draft')),
 
37
        (2, _('Public')),
 
38
    )
 
39
    title           = models.CharField(_('title'), max_length=200)
 
40
    slug            = models.SlugField(_('slug'), unique_for_date='publish')
 
41
    author          = models.ForeignKey(User, blank=True, null=True)
 
42
    body            = models.TextField(_('body'))
 
43
    tease           = models.TextField(_('tease'), blank=True)
 
44
    status          = models.IntegerField(_('status'), choices=STATUS_CHOICES, default=2)
 
45
    allow_comments  = models.BooleanField(_('allow comments'), default=True)
 
46
    publish         = models.DateTimeField(_('publish'))
 
47
    created         = models.DateTimeField(_('created'), auto_now_add=True)
 
48
    modified        = models.DateTimeField(_('modified'), auto_now=True)
 
49
    categories      = models.ManyToManyField(Category, blank=True)
 
50
    tags            = TagField()
 
51
    objects         = PublicManager()
 
52
 
 
53
    class Meta:
 
54
        verbose_name = _('post')
 
55
        verbose_name_plural = _('posts')
 
56
        db_table  = 'news_posts'
 
57
        ordering  = ('-publish',)
 
58
        get_latest_by = 'publish'
 
59
 
 
60
    class Admin:
 
61
        list_display  = ('title', 'publish', 'status')
 
62
        list_filter   = ('publish', 'categories', 'status')
 
63
        search_fields = ('title', 'body')
 
64
 
 
65
    def __unicode__(self):
 
66
        return u'%s' % self.title
 
67
 
 
68
    @permalink
 
69
    def get_absolute_url(self):
 
70
        return ('news_detail', None, {
 
71
            'year': self.publish.year,
 
72
            'month': self.publish.strftime('%b').lower(),
 
73
            'day': self.publish.day,
 
74
            'slug': self.slug
 
75
        })
 
76
    
 
77
    def get_previous_post(self):
 
78
        return self.get_previous_by_publish(status__gte=2)
 
79
    
 
80
    def get_next_post(self):
 
81
        return self.get_next_by_publish(status__gte=2)
 
82