PageRenderTime 128ms CodeModel.GetById 80ms app.highlight 27ms RepoModel.GetById 13ms app.codeStats 1ms

/tests/regressiontests/backends/models.py

https://code.google.com/p/mango-py/
Python | 71 lines | 47 code | 20 blank | 4 comment | 1 complexity | e58ce3dbbca3fc8ee544cc68cf201a4c MD5 | raw file
 1from django.contrib.contenttypes import generic
 2from django.contrib.contenttypes.models import ContentType
 3from django.db import models
 4from django.db import connection
 5
 6
 7class Square(models.Model):
 8    root = models.IntegerField()
 9    square = models.PositiveIntegerField()
10
11    def __unicode__(self):
12        return "%s ** 2 == %s" % (self.root, self.square)
13
14
15class Person(models.Model):
16    first_name = models.CharField(max_length=20)
17    last_name = models.CharField(max_length=20)
18
19    def __unicode__(self):
20        return u'%s %s' % (self.first_name, self.last_name)
21
22
23class SchoolClass(models.Model):
24    year = models.PositiveIntegerField()
25    day = models.CharField(max_length=9, blank=True)
26    last_updated = models.DateTimeField()
27
28# Unfortunately, the following model breaks MySQL hard.
29# Until #13711 is fixed, this test can't be run under MySQL.
30if connection.features.supports_long_model_names:
31    class VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ(models.Model):
32        class Meta:
33            # We need to use a short actual table name or
34            # we hit issue #8548 which we're not testing!
35            verbose_name = 'model_with_long_table_name'
36        primary_key_is_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.AutoField(primary_key=True)
37        charfield_is_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.CharField(max_length=100)
38        m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.ManyToManyField(Person,blank=True)
39
40
41class Tag(models.Model):
42    name = models.CharField(max_length=30)
43    content_type = models.ForeignKey(ContentType, related_name='backend_tags')
44    object_id = models.PositiveIntegerField()
45    content_object = generic.GenericForeignKey('content_type', 'object_id')
46
47
48class Post(models.Model):
49    name = models.CharField(max_length=30)
50    text = models.TextField()
51    tags = generic.GenericRelation('Tag')
52
53    class Meta:
54        db_table = 'CaseSensitive_Post'
55
56
57class Reporter(models.Model):
58    first_name = models.CharField(max_length=30)
59    last_name = models.CharField(max_length=30)
60
61    def __unicode__(self):
62        return u"%s %s" % (self.first_name, self.last_name)
63
64
65class Article(models.Model):
66    headline = models.CharField(max_length=100)
67    pub_date = models.DateField()
68    reporter = models.ForeignKey(Reporter)
69
70    def __unicode__(self):
71        return self.headline