2012-06-08 00:08:47 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2010-07-30 10:42:36 +08:00
|
|
|
from django.contrib.contenttypes import generic
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2011-10-14 02:51:33 +08:00
|
|
|
from django.db import models, connection
|
2012-08-12 18:32:08 +08:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2010-06-21 19:48:45 +08:00
|
|
|
|
2007-09-15 05:38:45 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2007-09-15 05:38:45 +08:00
|
|
|
class Square(models.Model):
|
|
|
|
root = models.IntegerField()
|
|
|
|
square = models.PositiveIntegerField()
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2007-09-15 05:38:45 +08:00
|
|
|
return "%s ** 2 == %s" % (self.root, self.square)
|
|
|
|
|
2010-06-21 19:48:45 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-01-05 06:51:22 +08:00
|
|
|
class Person(models.Model):
|
|
|
|
first_name = models.CharField(max_length=20)
|
|
|
|
last_name = models.CharField(max_length=20)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return '%s %s' % (self.first_name, self.last_name)
|
2008-01-05 06:51:22 +08:00
|
|
|
|
2010-06-21 19:48:45 +08:00
|
|
|
|
2010-02-24 23:29:25 +08:00
|
|
|
class SchoolClass(models.Model):
|
|
|
|
year = models.PositiveIntegerField()
|
|
|
|
day = models.CharField(max_length=9, blank=True)
|
|
|
|
last_updated = models.DateTimeField()
|
|
|
|
|
2010-06-21 19:48:45 +08:00
|
|
|
# Unfortunately, the following model breaks MySQL hard.
|
|
|
|
# Until #13711 is fixed, this test can't be run under MySQL.
|
2010-10-11 20:55:17 +08:00
|
|
|
if connection.features.supports_long_model_names:
|
2010-06-21 19:48:45 +08:00
|
|
|
class VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ(models.Model):
|
|
|
|
class Meta:
|
|
|
|
# We need to use a short actual table name or
|
|
|
|
# we hit issue #8548 which we're not testing!
|
|
|
|
verbose_name = 'model_with_long_table_name'
|
|
|
|
primary_key_is_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.AutoField(primary_key=True)
|
|
|
|
charfield_is_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.CharField(max_length=100)
|
|
|
|
m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.ManyToManyField(Person,blank=True)
|
|
|
|
|
|
|
|
|
2010-07-30 10:42:36 +08:00
|
|
|
class Tag(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
2010-07-30 11:49:58 +08:00
|
|
|
content_type = models.ForeignKey(ContentType, related_name='backend_tags')
|
2010-07-30 10:42:36 +08:00
|
|
|
object_id = models.PositiveIntegerField()
|
|
|
|
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
|
|
|
|
|
|
|
|
|
|
|
class Post(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
|
|
|
text = models.TextField()
|
|
|
|
tags = generic.GenericRelation('Tag')
|
|
|
|
|
2010-07-30 10:43:01 +08:00
|
|
|
class Meta:
|
|
|
|
db_table = 'CaseSensitive_Post'
|
2010-07-30 10:42:36 +08:00
|
|
|
|
2007-09-16 18:04:26 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2010-10-23 08:01:22 +08:00
|
|
|
class Reporter(models.Model):
|
|
|
|
first_name = models.CharField(max_length=30)
|
|
|
|
last_name = models.CharField(max_length=30)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return "%s %s" % (self.first_name, self.last_name)
|
2010-10-23 08:01:22 +08:00
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2010-10-23 08:01:22 +08:00
|
|
|
class Article(models.Model):
|
|
|
|
headline = models.CharField(max_length=100)
|
|
|
|
pub_date = models.DateField()
|
|
|
|
reporter = models.ForeignKey(Reporter)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-10-23 08:01:22 +08:00
|
|
|
return self.headline
|