2017-02-07 04:49:31 +00:00
|
|
|
import datetime
|
|
|
|
import uuid
|
|
|
|
from decimal import Decimal
|
|
|
|
|
2011-09-09 19:22:28 +00:00
|
|
|
from django.db import models
|
2017-02-07 04:49:31 +00:00
|
|
|
from django.utils import timezone
|
2011-09-09 19:22:28 +00:00
|
|
|
|
2017-02-13 13:58:10 +00:00
|
|
|
try:
|
|
|
|
from PIL import Image
|
|
|
|
except ImportError:
|
|
|
|
Image = None
|
|
|
|
|
2011-09-09 19:22:28 +00:00
|
|
|
|
|
|
|
class Country(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
iso_two_letter = models.CharField(max_length=2)
|
2017-02-24 15:54:10 +00:00
|
|
|
description = models.TextField()
|
2011-09-09 19:22:28 +00:00
|
|
|
|
2020-06-14 16:58:06 +00:00
|
|
|
class Meta:
|
|
|
|
constraints = [
|
|
|
|
models.UniqueConstraint(
|
2022-02-03 19:24:19 +00:00
|
|
|
fields=["iso_two_letter", "name"],
|
|
|
|
name="country_name_iso_unique",
|
2020-06-14 16:58:06 +00:00
|
|
|
),
|
|
|
|
]
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2015-06-18 14:12:07 +00:00
|
|
|
class ProxyCountry(Country):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
|
|
|
class ProxyProxyCountry(ProxyCountry):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
|
|
|
class ProxyMultiCountry(ProxyCountry):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class ProxyMultiProxyCountry(ProxyMultiCountry):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
|
|
|
|
2011-09-09 19:22:28 +00:00
|
|
|
class Place(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
abstract = True
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-09-09 19:22:28 +00:00
|
|
|
class Restaurant(Place):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-09-09 19:22:28 +00:00
|
|
|
class Pizzeria(Restaurant):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-09-09 19:22:28 +00:00
|
|
|
class State(models.Model):
|
2012-04-29 01:22:05 +00:00
|
|
|
two_letter_code = models.CharField(max_length=2, primary_key=True)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-04-29 01:22:05 +00:00
|
|
|
class TwoFields(models.Model):
|
|
|
|
f1 = models.IntegerField(unique=True)
|
|
|
|
f2 = models.IntegerField(unique=True)
|
2020-06-14 16:58:06 +00:00
|
|
|
name = models.CharField(max_length=15, null=True)
|
|
|
|
|
|
|
|
|
2022-11-22 09:34:55 +00:00
|
|
|
class FieldsWithDbColumns(models.Model):
|
|
|
|
rank = models.IntegerField(unique=True, db_column="rAnK")
|
|
|
|
name = models.CharField(max_length=15, null=True, db_column="oTheRNaMe")
|
|
|
|
|
|
|
|
|
2020-06-14 16:58:06 +00:00
|
|
|
class UpsertConflict(models.Model):
|
|
|
|
number = models.IntegerField(unique=True)
|
|
|
|
rank = models.IntegerField()
|
|
|
|
name = models.CharField(max_length=15)
|
2015-10-09 01:14:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NoFields(models.Model):
|
|
|
|
pass
|
2017-02-07 04:49:31 +00:00
|
|
|
|
|
|
|
|
2020-02-28 06:50:24 +00:00
|
|
|
class SmallAutoFieldModel(models.Model):
|
|
|
|
id = models.SmallAutoField(primary_key=True)
|
|
|
|
|
|
|
|
|
|
|
|
class BigAutoFieldModel(models.Model):
|
|
|
|
id = models.BigAutoField(primary_key=True)
|
|
|
|
|
|
|
|
|
2017-02-07 04:49:31 +00:00
|
|
|
class NullableFields(models.Model):
|
|
|
|
# Fields in db.backends.oracle.BulkInsertMapper
|
|
|
|
big_int_filed = models.BigIntegerField(null=True, default=1)
|
2022-02-03 19:24:19 +00:00
|
|
|
binary_field = models.BinaryField(null=True, default=b"data")
|
2017-02-07 04:49:31 +00:00
|
|
|
date_field = models.DateField(null=True, default=timezone.now)
|
|
|
|
datetime_field = models.DateTimeField(null=True, default=timezone.now)
|
2022-02-03 19:24:19 +00:00
|
|
|
decimal_field = models.DecimalField(
|
|
|
|
null=True, max_digits=2, decimal_places=1, default=Decimal("1.1")
|
|
|
|
)
|
2017-02-07 04:49:31 +00:00
|
|
|
duration_field = models.DurationField(null=True, default=datetime.timedelta(1))
|
|
|
|
float_field = models.FloatField(null=True, default=3.2)
|
|
|
|
integer_field = models.IntegerField(null=True, default=2)
|
2017-05-06 14:56:28 +00:00
|
|
|
null_boolean_field = models.BooleanField(null=True, default=False)
|
2022-02-03 19:24:19 +00:00
|
|
|
positive_big_integer_field = models.PositiveBigIntegerField(
|
|
|
|
null=True, default=2**63 - 1
|
|
|
|
)
|
2017-02-07 04:49:31 +00:00
|
|
|
positive_integer_field = models.PositiveIntegerField(null=True, default=3)
|
2022-02-03 19:24:19 +00:00
|
|
|
positive_small_integer_field = models.PositiveSmallIntegerField(
|
|
|
|
null=True, default=4
|
|
|
|
)
|
2017-02-07 04:49:31 +00:00
|
|
|
small_integer_field = models.SmallIntegerField(null=True, default=5)
|
|
|
|
time_field = models.TimeField(null=True, default=timezone.now)
|
2020-02-28 06:50:24 +00:00
|
|
|
auto_field = models.ForeignKey(NoFields, on_delete=models.CASCADE, null=True)
|
2022-02-03 19:24:19 +00:00
|
|
|
small_auto_field = models.ForeignKey(
|
|
|
|
SmallAutoFieldModel, on_delete=models.CASCADE, null=True
|
|
|
|
)
|
|
|
|
big_auto_field = models.ForeignKey(
|
|
|
|
BigAutoFieldModel, on_delete=models.CASCADE, null=True
|
|
|
|
)
|
2017-02-07 04:49:31 +00:00
|
|
|
# Fields not required in BulkInsertMapper
|
2022-02-03 19:24:19 +00:00
|
|
|
char_field = models.CharField(null=True, max_length=4, default="char")
|
|
|
|
email_field = models.EmailField(null=True, default="user@example.com")
|
|
|
|
file_field = models.FileField(null=True, default="file.txt")
|
|
|
|
file_path_field = models.FilePathField(path="/tmp", null=True, default="file.txt")
|
|
|
|
generic_ip_address_field = models.GenericIPAddressField(
|
|
|
|
null=True, default="127.0.0.1"
|
|
|
|
)
|
2017-02-13 13:58:10 +00:00
|
|
|
if Image:
|
2022-02-03 19:24:19 +00:00
|
|
|
image_field = models.ImageField(null=True, default="image.jpg")
|
|
|
|
slug_field = models.SlugField(null=True, default="slug")
|
|
|
|
text_field = models.TextField(null=True, default="text")
|
|
|
|
url_field = models.URLField(null=True, default="/")
|
2017-02-07 04:49:31 +00:00
|
|
|
uuid_field = models.UUIDField(null=True, default=uuid.uuid4)
|
2020-06-14 16:58:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RelatedModel(models.Model):
|
|
|
|
name = models.CharField(max_length=15, null=True)
|
|
|
|
country = models.OneToOneField(Country, models.CASCADE, primary_key=True)
|
|
|
|
big_auto_fields = models.ManyToManyField(BigAutoFieldModel)
|