import datetime from django.contrib.auth.models import User from django.db import models from sorl.thumbnail import ImageField 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 Creole als Markup 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 = ImageField('Bild', upload_to='news', blank=True) 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})