import datetime from django.contrib.auth.models import User from django.db import models from sorl.thumbnail import ImageField from utils import render_creole class Project(models.Model): """A project. """ name = models.CharField('Name', max_length=100) slug = models.SlugField('Slug', unique=True) description = models.TextField('Beschreibung', help_text='Es kann Creole als Markup benutzt werden.') description_html = models.TextField(editable=False) contact_email = models.EmailField('E-Mail', blank=True) contact_url = models.URLField('URL', blank=True) contact_user = models.ForeignKey(User, verbose_name='Ansprechpartner') image = ImageField('Bild', upload_to='projects', blank=True) date_created = models.DateTimeField('Erstellungsdatum', editable=False) date_updated = models.DateTimeField('Aktualisierungsdatum', editable=False) class Meta: ordering = ['name'] verbose_name = 'Projekt' verbose_name_plural = 'Projekte' def __unicode__(self): return self.name def save(self, *args, **kwargs): if not self.id: self.date_created = datetime.datetime.now() self.date_updated = datetime.datetime.now() self.description_html = render_creole(self.description) return super(Project, self).save(*args, **kwargs) @models.permalink def get_absolute_url(self): return ('projects_detail', (), {'slug': self.slug})