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