X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/793b39c86e9583467f1cbc41f8b1a4677d079f23..9c42ef76e42e997b52c8b02eae058e345d103d80:/apps/dvcs/models.py?ds=inline diff --git a/apps/dvcs/models.py b/apps/dvcs/models.py index 9c9d350b..ef11dbe8 100644 --- a/apps/dvcs/models.py +++ b/apps/dvcs/models.py @@ -1,3 +1,5 @@ +from datetime import datetime + from django.db import models from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ @@ -26,7 +28,8 @@ class Change(models.Model): related_name="merge_children") description = models.TextField(blank=True, default='') - created_at = models.DateTimeField(auto_now_add=True, db_index=True) + created_at = models.DateTimeField(editable=False, db_index=True, + default=datetime.now) class Meta: ordering = ('created_at',) @@ -158,12 +161,12 @@ class Document(models.Model): return self.head def history(self): - return self.change_set.filter(revision__gt=0) + return self.change_set.filter(revision__gt=-1) def revision(self): rev = self.change_set.aggregate( models.Max('revision'))['revision__max'] - return rev if rev is not None else 0 + return rev if rev is not None else -1 def at_revision(self, rev): if rev: @@ -173,12 +176,15 @@ class Document(models.Model): @staticmethod def listener_initial_commit(sender, instance, created, **kwargs): + # run for Document and its subclasses + if not isinstance(instance, Document): + return if created: instance.head = Change.objects.create( - revision=0, + revision=-1, author=instance.creator, patch=Change.make_patch('', ''), tree=instance) instance.save() -models.signals.post_save.connect(Document.listener_initial_commit, sender=Document) +models.signals.post_save.connect(Document.listener_initial_commit)