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 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 = 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})