total mess: some random experiments with images and lqc's dvcs
[redakcja.git] / apps / wiki_img / models.py
diff --git a/apps/wiki_img/models.py b/apps/wiki_img/models.py
new file mode 100644 (file)
index 0000000..dd16a87
--- /dev/null
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from django.db import models
+from django.contrib.auth.models import User
+from django.utils.translation import ugettext_lazy as _
+from dvcs.models import Document
+
+
+class ImageDocument(models.Model):
+    slug = models.SlugField(_('slug'), max_length=120)
+    name = models.CharField(_('name'), max_length=120)
+    image = models.ImageField(_('image'), upload_to='wiki_img')
+    doc = models.OneToOneField(Document, null=True, blank=True)
+    creator = models.ForeignKey(User, null=True, blank=True)
+
+    @staticmethod
+    def listener_initial_commit(sender, instance, created, **kwargs):
+        if created:
+            instance.doc = Document.objects.create(creator=instance.creator)
+            instance.save()
+
+    def __unicode__(self):
+        return self.name
+
+
+models.signals.post_save.connect(ImageDocument.listener_initial_commit, sender=ImageDocument)