mirror of
https://github.com/django/django.git
synced 2024-12-25 02:26:12 +00:00
d4a0b27838
* Renamed the __unicode__ methods * Applied the python_2_unicode_compatible decorator * Removed the StrAndUnicode mix-in that is superseded by python_2_unicode_compatible * Kept the __unicode__ methods in classes that specifically test it under Python 2
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from __future__ import unicode_literals
|
|
|
|
import copy
|
|
import datetime
|
|
|
|
from django.contrib.auth.models import User
|
|
from django.db import models
|
|
from django.utils.encoding import python_2_unicode_compatible
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
class RevisionableModel(models.Model):
|
|
base = models.ForeignKey('self', null=True)
|
|
title = models.CharField(blank=True, max_length=255)
|
|
when = models.DateTimeField(default=datetime.datetime.now)
|
|
|
|
def __str__(self):
|
|
return "%s (%s, %s)" % (self.title, self.id, self.base.id)
|
|
|
|
def save(self, *args, **kwargs):
|
|
super(RevisionableModel, self).save(*args, **kwargs)
|
|
if not self.base:
|
|
self.base = self
|
|
kwargs.pop('force_insert', None)
|
|
kwargs.pop('force_update', None)
|
|
super(RevisionableModel, self).save(*args, **kwargs)
|
|
|
|
def new_revision(self):
|
|
new_revision = copy.copy(self)
|
|
new_revision.pk = None
|
|
return new_revision
|
|
|
|
class Order(models.Model):
|
|
created_by = models.ForeignKey(User)
|
|
text = models.TextField()
|
|
|
|
@python_2_unicode_compatible
|
|
class TestObject(models.Model):
|
|
first = models.CharField(max_length=20)
|
|
second = models.CharField(max_length=20)
|
|
third = models.CharField(max_length=20)
|
|
|
|
def __str__(self):
|
|
return 'TestObject: %s,%s,%s' % (self.first,self.second,self.third)
|
|
|