2011-03-28 04:11:19 +02:00
|
|
|
import copy
|
2008-09-28 06:36:10 +02:00
|
|
|
import datetime
|
2008-06-30 08:24:21 +02:00
|
|
|
|
2008-08-17 22:07:59 +02:00
|
|
|
from django.contrib.auth.models import User
|
2008-06-30 08:24:21 +02:00
|
|
|
from django.db import models
|
|
|
|
|
2011-10-13 20:51:33 +02:00
|
|
|
|
2008-06-30 08:24:21 +02:00
|
|
|
class RevisionableModel(models.Model):
|
|
|
|
base = models.ForeignKey('self', null=True)
|
|
|
|
title = models.CharField(blank=True, max_length=255)
|
2008-09-28 06:36:10 +02:00
|
|
|
when = models.DateTimeField(default=datetime.datetime.now)
|
2008-06-30 08:24:21 +02:00
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
return u"%s (%s, %s)" % (self.title, self.id, self.base.id)
|
|
|
|
|
2009-12-22 16:18:51 +01:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
super(RevisionableModel, self).save(*args, **kwargs)
|
2008-06-30 08:24:21 +02:00
|
|
|
if not self.base:
|
|
|
|
self.base = self
|
2009-12-22 16:18:51 +01:00
|
|
|
kwargs.pop('force_insert', None)
|
|
|
|
kwargs.pop('force_update', None)
|
|
|
|
super(RevisionableModel, self).save(*args, **kwargs)
|
2008-06-30 08:24:21 +02:00
|
|
|
|
|
|
|
def new_revision(self):
|
|
|
|
new_revision = copy.copy(self)
|
|
|
|
new_revision.pk = None
|
|
|
|
return new_revision
|
|
|
|
|
2008-08-18 00:38:36 +02:00
|
|
|
class Order(models.Model):
|
|
|
|
created_by = models.ForeignKey(User)
|
|
|
|
text = models.TextField()
|
|
|
|
|
2009-02-16 13:28:37 +01:00
|
|
|
class TestObject(models.Model):
|
|
|
|
first = models.CharField(max_length=20)
|
|
|
|
second = models.CharField(max_length=20)
|
|
|
|
third = models.CharField(max_length=20)
|
|
|
|
|
2009-04-30 17:40:09 +02:00
|
|
|
def __unicode__(self):
|
|
|
|
return u'TestObject: %s,%s,%s' % (self.first,self.second,self.third)
|
|
|
|
|