1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import datetime
from django.contrib.auth.models import User
from django.db import models
from projects.models import Project
from utils import render_creole
class News(models.Model):
"""A news item.
"""
title = models.CharField('Titel', max_length=255)
slug = models.SlugField('Slug', unique=True)
content = models.TextField('Inhalt',
help_text='Es kann <a href="http://wikicreole.org/" target="blank">Creole als Markup</a> benutzt werden.')
content_html = models.TextField(editable=False)
projects = models.ManyToManyField(Project, blank=True,
related_name='news', verbose_name='Projekte')
author = models.ForeignKey(User, editable=False, verbose_name='Autor')
image = models.ImageField('Bild', upload_to='news',
height_field='image_height', width_field='image_width', blank=True)
image_height = models.IntegerField(default=0, editable=False)
image_width = models.IntegerField(default=0, editable=False)
date_created = models.DateTimeField('Erstellungsdatum', editable=False)
date_updated = models.DateTimeField('Aktualisierungsdatum', editable=False)
class Meta:
ordering = ['-date_created']
verbose_name = 'News'
verbose_name_plural = 'News'
def __unicode__(self):
return self.title
def save(self, *args, **kwargs):
if not self.id:
self.date_created = datetime.datetime.now()
self.date_updated = datetime.datetime.now()
self.content_html = render_creole(self.content)
super(News, self).save(*args, **kwargs)
@models.permalink
def get_absolute_url(self):
return ('news_detail', (), {'slug': self.slug})
|