2014-01-22 14:43:33 +08:00
|
|
|
from django.contrib.contenttypes.fields import (
|
2015-01-28 20:35:27 +08:00
|
|
|
GenericForeignKey, GenericRelation,
|
2014-01-22 14:43:33 +08:00
|
|
|
)
|
2010-07-30 10:42:36 +08:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2014-06-10 20:04:19 +08:00
|
|
|
from django.db import models
|
2010-06-21 19:48:45 +08:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2020-11-11 06:22:30 +08:00
|
|
|
class SchoolClassManager(models.Manager):
|
|
|
|
def get_queryset(self):
|
|
|
|
return super().get_queryset().exclude(year=1000)
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2020-11-11 06:22:30 +08:00
|
|
|
objects = SchoolClassManager()
|
|
|
|
|
2014-06-10 20:04:19 +08:00
|
|
|
|
|
|
|
class VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ(models.Model):
|
|
|
|
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-06-21 19:48:45 +08:00
|
|
|
|
|
|
|
|
2010-07-30 10:42:36 +08:00
|
|
|
class Tag(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
2015-07-22 22:43:21 +08:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE, related_name='backend_tags')
|
2010-07-30 10:42:36 +08:00
|
|
|
object_id = models.PositiveIntegerField()
|
2014-01-22 14:43:33 +08:00
|
|
|
content_object = GenericForeignKey('content_type', 'object_id')
|
2010-07-30 10:42:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Post(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
|
|
|
text = models.TextField()
|
2014-01-22 14:43:33 +08:00
|
|
|
tags = GenericRelation('Tag')
|
2010-07-30 10:42:36 +08:00
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
2013-08-02 02:09:47 +08:00
|
|
|
class ReporterProxy(Reporter):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
2010-10-23 08:01:22 +08:00
|
|
|
class Article(models.Model):
|
|
|
|
headline = models.CharField(max_length=100)
|
|
|
|
pub_date = models.DateField()
|
2015-07-22 22:43:21 +08:00
|
|
|
reporter = models.ForeignKey(Reporter, models.CASCADE)
|
|
|
|
reporter_proxy = models.ForeignKey(
|
|
|
|
ReporterProxy,
|
|
|
|
models.SET_NULL,
|
|
|
|
null=True,
|
|
|
|
related_name='reporter_proxy',
|
|
|
|
)
|
2010-10-23 08:01:22 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2010-10-23 08:01:22 +08:00
|
|
|
return self.headline
|
2013-01-11 13:57:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Item(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
|
|
|
date = models.DateField()
|
|
|
|
time = models.TimeField()
|
|
|
|
last_modified = models.DateTimeField()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2013-02-21 03:27:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Object(models.Model):
|
2013-03-08 03:24:51 +08:00
|
|
|
related_objects = models.ManyToManyField("self", db_constraint=False, symmetrical=False)
|
2019-12-02 07:42:06 +08:00
|
|
|
obj_ref = models.ForeignKey('ObjectReference', models.CASCADE, null=True)
|
2013-03-08 03:24:51 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.id)
|
2013-02-21 03:27:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ObjectReference(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
obj = models.ForeignKey(Object, models.CASCADE, db_constraint=False)
|
2013-02-21 03:27:32 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.obj_id)
|
2014-06-05 23:06:50 +08:00
|
|
|
|
|
|
|
|
2019-12-02 08:16:32 +08:00
|
|
|
class ObjectSelfReference(models.Model):
|
|
|
|
key = models.CharField(max_length=3, unique=True)
|
|
|
|
obj = models.ForeignKey('ObjectSelfReference', models.SET_NULL, null=True)
|
|
|
|
|
|
|
|
|
2019-12-02 08:16:32 +08:00
|
|
|
class CircularA(models.Model):
|
|
|
|
key = models.CharField(max_length=3, unique=True)
|
|
|
|
obj = models.ForeignKey('CircularB', models.SET_NULL, null=True)
|
|
|
|
|
|
|
|
def natural_key(self):
|
|
|
|
return (self.key,)
|
|
|
|
|
|
|
|
|
|
|
|
class CircularB(models.Model):
|
|
|
|
key = models.CharField(max_length=3, unique=True)
|
|
|
|
obj = models.ForeignKey('CircularA', models.SET_NULL, null=True)
|
|
|
|
|
|
|
|
def natural_key(self):
|
|
|
|
return (self.key,)
|
|
|
|
|
|
|
|
|
2014-06-05 23:06:50 +08:00
|
|
|
class RawData(models.Model):
|
|
|
|
raw_data = models.BinaryField()
|
2017-11-27 11:39:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Author(models.Model):
|
|
|
|
name = models.CharField(max_length=255, unique=True)
|
|
|
|
|
|
|
|
|
|
|
|
class Book(models.Model):
|
|
|
|
author = models.ForeignKey(Author, models.CASCADE, to_field='name')
|
2020-12-28 13:45:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
class SQLKeywordsModel(models.Model):
|
|
|
|
id = models.AutoField(primary_key=True, db_column='select')
|
|
|
|
reporter = models.ForeignKey(Reporter, models.CASCADE, db_column='where')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = 'order'
|