PageRenderTime 43ms CodeModel.GetById 35ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/extra_regress/models.py

https://code.google.com/p/mango-py/
Python | 40 lines | 30 code | 10 blank | 0 comment | 2 complexity | 1e70cefbed7a159f9ea1e70020a1bd26 MD5 | raw file
 1import datetime
 2
 3import django.utils.copycompat as copy
 4
 5from django.contrib.auth.models import User
 6from django.db import models
 7
 8class RevisionableModel(models.Model):
 9    base = models.ForeignKey('self', null=True)
10    title = models.CharField(blank=True, max_length=255)
11    when = models.DateTimeField(default=datetime.datetime.now)
12
13    def __unicode__(self):
14        return u"%s (%s, %s)" % (self.title, self.id, self.base.id)
15
16    def save(self, *args, **kwargs):
17        super(RevisionableModel, self).save(*args, **kwargs)
18        if not self.base:
19            self.base = self
20            kwargs.pop('force_insert', None)
21            kwargs.pop('force_update', None)
22            super(RevisionableModel, self).save(*args, **kwargs)
23
24    def new_revision(self):
25        new_revision = copy.copy(self)
26        new_revision.pk = None
27        return new_revision
28
29class Order(models.Model):
30    created_by = models.ForeignKey(User)
31    text = models.TextField()
32
33class TestObject(models.Model):
34    first = models.CharField(max_length=20)
35    second = models.CharField(max_length=20)
36    third = models.CharField(max_length=20)
37
38    def __unicode__(self):
39        return u'TestObject: %s,%s,%s' % (self.first,self.second,self.third)
40