2020-07-18 19:17:39 +08:00
|
|
|
from django.db import connection, models
|
2022-04-16 21:29:51 +08:00
|
|
|
from django.db.models.functions import Lower
|
2011-01-24 22:58:05 +08:00
|
|
|
|
2011-01-24 23:18:56 +08:00
|
|
|
|
|
|
|
class People(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey("self", models.CASCADE)
|
2011-01-24 23:18:56 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-01-24 23:18:56 +08:00
|
|
|
class Message(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
from_field = models.ForeignKey(People, models.CASCADE, db_column="from_id")
|
2022-07-05 02:28:44 +08:00
|
|
|
author = models.ForeignKey(People, models.CASCADE, related_name="message_authors")
|
2012-02-05 15:51:37 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2012-02-05 15:51:37 +08:00
|
|
|
class PeopleData(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
people_pk = models.ForeignKey(People, models.CASCADE, primary_key=True)
|
2012-02-05 15:51:37 +08:00
|
|
|
ssn = models.CharField(max_length=11)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2012-02-05 15:51:37 +08:00
|
|
|
class PeopleMoreData(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
people_unique = models.ForeignKey(People, models.CASCADE, unique=True)
|
2016-12-13 19:38:09 +08:00
|
|
|
message = models.ForeignKey(Message, models.CASCADE, blank=True, null=True)
|
2012-02-05 15:51:37 +08:00
|
|
|
license = models.CharField(max_length=255)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2021-10-30 23:08:06 +08:00
|
|
|
class ForeignKeyToField(models.Model):
|
|
|
|
to_field_fk = models.ForeignKey(
|
|
|
|
PeopleMoreData,
|
|
|
|
models.CASCADE,
|
|
|
|
to_field="people_unique",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2012-02-12 04:53:48 +08:00
|
|
|
class DigitsInColumnName(models.Model):
|
|
|
|
all_digits = models.CharField(max_length=11, db_column="123")
|
|
|
|
leading_digit = models.CharField(max_length=11, db_column="4extra")
|
|
|
|
leading_digits = models.CharField(max_length=11, db_column="45extra")
|
2012-08-24 03:07:56 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2014-07-06 02:48:57 +08:00
|
|
|
class SpecialName(models.Model):
|
2012-08-24 03:07:56 +08:00
|
|
|
field = models.IntegerField(db_column="field")
|
2012-08-24 04:50:25 +08:00
|
|
|
# Underscores
|
2012-08-24 03:07:56 +08:00
|
|
|
field_field_0 = models.IntegerField(db_column="Field_")
|
|
|
|
field_field_1 = models.IntegerField(db_column="Field__")
|
|
|
|
field_field_2 = models.IntegerField(db_column="__field")
|
2012-08-24 04:50:25 +08:00
|
|
|
# Other chars
|
|
|
|
prc_x = models.IntegerField(db_column="prc(%) x")
|
2013-04-02 01:51:53 +08:00
|
|
|
non_ascii = models.IntegerField(db_column="tamaño")
|
2013-02-01 03:34:36 +08:00
|
|
|
|
2014-07-06 02:48:57 +08:00
|
|
|
class Meta:
|
|
|
|
db_table = "inspectdb_special.table name"
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-02-01 03:34:36 +08:00
|
|
|
class ColumnTypes(models.Model):
|
|
|
|
id = models.AutoField(primary_key=True)
|
2013-02-01 09:00:25 +08:00
|
|
|
big_int_field = models.BigIntegerField()
|
2013-08-12 04:19:09 +08:00
|
|
|
bool_field = models.BooleanField(default=False)
|
2017-05-06 22:56:28 +08:00
|
|
|
null_bool_field = models.BooleanField(null=True)
|
2013-02-01 09:00:25 +08:00
|
|
|
char_field = models.CharField(max_length=10)
|
2014-10-21 02:05:43 +08:00
|
|
|
null_char_field = models.CharField(max_length=10, blank=True, null=True)
|
2013-02-01 09:00:25 +08:00
|
|
|
date_field = models.DateField()
|
|
|
|
date_time_field = models.DateTimeField()
|
|
|
|
decimal_field = models.DecimalField(max_digits=6, decimal_places=1)
|
|
|
|
email_field = models.EmailField()
|
|
|
|
file_field = models.FileField(upload_to="unused")
|
|
|
|
file_path_field = models.FilePathField()
|
|
|
|
float_field = models.FloatField()
|
|
|
|
int_field = models.IntegerField()
|
2017-01-19 18:00:41 +08:00
|
|
|
gen_ip_address_field = models.GenericIPAddressField(protocol="ipv4")
|
2019-10-16 20:32:12 +08:00
|
|
|
pos_big_int_field = models.PositiveBigIntegerField()
|
2013-02-01 09:00:25 +08:00
|
|
|
pos_int_field = models.PositiveIntegerField()
|
|
|
|
pos_small_int_field = models.PositiveSmallIntegerField()
|
|
|
|
slug_field = models.SlugField()
|
|
|
|
small_int_field = models.SmallIntegerField()
|
|
|
|
text_field = models.TextField()
|
|
|
|
time_field = models.TimeField()
|
|
|
|
url_field = models.URLField()
|
2016-07-20 15:01:57 +08:00
|
|
|
uuid_field = models.UUIDField()
|
2014-07-15 04:42:05 +08:00
|
|
|
|
|
|
|
|
2019-06-09 08:56:37 +08:00
|
|
|
class JSONFieldColumnType(models.Model):
|
|
|
|
json_field = models.JSONField()
|
|
|
|
null_json_field = models.JSONField(blank=True, null=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
required_db_features = {
|
|
|
|
"can_introspect_json_field",
|
|
|
|
"supports_json_field",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-18 19:17:39 +08:00
|
|
|
test_collation = connection.features.test_collations.get("non_default")
|
|
|
|
|
|
|
|
|
|
|
|
class CharFieldDbCollation(models.Model):
|
|
|
|
char_field = models.CharField(max_length=10, db_collation=test_collation)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
required_db_features = {"supports_collation_on_charfield"}
|
|
|
|
|
|
|
|
|
|
|
|
class TextFieldDbCollation(models.Model):
|
|
|
|
text_field = models.TextField(db_collation=test_collation)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
required_db_features = {"supports_collation_on_textfield"}
|
|
|
|
|
|
|
|
|
2022-11-11 02:31:31 +08:00
|
|
|
class CharFieldUnlimited(models.Model):
|
|
|
|
char_field = models.CharField(max_length=None)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
required_db_features = {"supports_unlimited_charfield"}
|
|
|
|
|
|
|
|
|
2014-07-15 04:42:05 +08:00
|
|
|
class UniqueTogether(models.Model):
|
|
|
|
field1 = models.IntegerField()
|
|
|
|
field2 = models.CharField(max_length=10)
|
2015-11-07 00:29:23 +08:00
|
|
|
from_field = models.IntegerField(db_column="from")
|
|
|
|
non_unique = models.IntegerField(db_column="non__unique_column")
|
|
|
|
non_unique_0 = models.IntegerField(db_column="non_unique__column")
|
2014-07-15 04:42:05 +08:00
|
|
|
|
|
|
|
class Meta:
|
2015-11-07 00:29:23 +08:00
|
|
|
unique_together = [
|
|
|
|
("field1", "field2"),
|
|
|
|
("from_field", "field1"),
|
|
|
|
("non_unique", "non_unique_0"),
|
|
|
|
]
|
2022-04-16 21:29:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
class FuncUniqueConstraint(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
rank = models.IntegerField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
constraints = [
|
|
|
|
models.UniqueConstraint(
|
|
|
|
Lower("name"), models.F("rank"), name="index_lower_name"
|
|
|
|
)
|
|
|
|
]
|
|
|
|
required_db_features = {"supports_expression_indexes"}
|
2022-10-16 13:59:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
class DbComment(models.Model):
|
|
|
|
rank = models.IntegerField(db_comment="'Rank' column comment")
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table_comment = "Custom table comment"
|
|
|
|
required_db_features = {"supports_comments"}
|