total mess: some random experiments with images and lqc's dvcs
[redakcja.git] / apps / wiki_img / models.py
1 # -*- coding: utf-8 -*-
2 #
3 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 #
6 from django.db import models
7 from django.contrib.auth.models import User
8 from django.utils.translation import ugettext_lazy as _
9 from dvcs.models import Document
10
11
12 class ImageDocument(models.Model):
13     slug = models.SlugField(_('slug'), max_length=120)
14     name = models.CharField(_('name'), max_length=120)
15     image = models.ImageField(_('image'), upload_to='wiki_img')
16     doc = models.OneToOneField(Document, null=True, blank=True)
17     creator = models.ForeignKey(User, null=True, blank=True)
18
19     @staticmethod
20     def listener_initial_commit(sender, instance, created, **kwargs):
21         if created:
22             instance.doc = Document.objects.create(creator=instance.creator)
23             instance.save()
24
25     def __unicode__(self):
26         return self.name
27
28
29 models.signals.post_save.connect(ImageDocument.listener_initial_commit, sender=ImageDocument)