2011-03-28 02:11:19 +00:00
|
|
|
import copy
|
2008-09-28 04:36:10 +00:00
|
|
|
import datetime
|
2008-06-30 06:24:21 +00:00
|
|
|
|
2008-08-17 20:07:59 +00:00
|
|
|
from django.contrib.auth.models import User
|
2008-06-30 06:24:21 +00:00
|
|
|
from django.db import models
|
|
|
|
|
2011-10-13 18:51:33 +00:00
|
|
|
|
2008-06-30 06:24:21 +00:00
|
|
|
class RevisionableModel(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
base = models.ForeignKey("self", models.SET_NULL, null=True)
|
2008-06-30 06:24:21 +00:00
|
|
|
title = models.CharField(blank=True, max_length=255)
|
2008-09-28 04:36:10 +00:00
|
|
|
when = models.DateTimeField(default=datetime.datetime.now)
|
2008-06-30 06:24:21 +00:00
|
|
|
|
2023-06-22 12:53:11 +00:00
|
|
|
def save(self, *args, force_insert=False, force_update=False, **kwargs):
|
2017-02-01 16:41:56 +00:00
|
|
|
super().save(
|
|
|
|
*args, force_insert=force_insert, force_update=force_update, **kwargs
|
|
|
|
)
|
2008-06-30 06:24:21 +00:00
|
|
|
if not self.base:
|
|
|
|
self.base = self
|
2017-01-21 13:13:44 +00:00
|
|
|
super().save(*args, **kwargs)
|
2008-06-30 06:24:21 +00:00
|
|
|
|
|
|
|
def new_revision(self):
|
|
|
|
new_revision = copy.copy(self)
|
|
|
|
new_revision.pk = None
|
|
|
|
return new_revision
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2008-08-17 22:38:36 +00:00
|
|
|
class Order(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
created_by = models.ForeignKey(User, models.CASCADE)
|
2008-08-17 22:38:36 +00:00
|
|
|
text = models.TextField()
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2009-02-16 12:28:37 +00: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 10:32:08 +00:00
|
|
|
def __str__(self):
|
2013-10-26 19:15:03 +00:00
|
|
|
return "TestObject: %s,%s,%s" % (self.first, self.second, self.third)
|