django-cachalot/cachalot/tests/models.py
Andrew-Chen-Wang d699c5b8c3 Squashed commit of the following:
commit 4a33e7b68196bf6e0ee0b7f942a992532495b616
Author: Andrew-Chen-Wang <acwangpython@gmail.com>
Date:   Mon Aug 10 16:04:26 2020 -0400

    Replace f-strings with join for Python 3.5

commit dcb33232d605c01025469e776c4ed8eb6ae0a326
Author: Andrew-Chen-Wang <acwangpython@gmail.com>
Date:   Mon Aug 10 15:55:09 2020 -0400

    Fix sql_flush for dj versions below 3.1
    * Removed any other instances of JSONField for Django 3.1 removed many things like JsonAdapter in favor of regular json module

commit 74195e9ff5a52dba2449a55e543a27ebd99e4fc9
Author: Andrew-Chen-Wang <acwangpython@gmail.com>
Date:   Mon Aug 10 09:17:03 2020 -0400

    Add Django 3.1 to Travis
    * Specify Django version when checking if JSONField exists

commit da5c1fa4c8b2f2efba0b12d7b27460c544e2473a
Author: Andrew-Chen-Wang <acwangpython@gmail.com>
Date:   Wed Aug 5 17:39:58 2020 -0400

    Added support for Django 3.1
    * Some fields were removed, others were deprecated. They are now in a list of deprecation to follow. Some new fields were added like PositiveBigIntegerField that won't be tested
    * monkey_patch.py has a try/except import for EmptyResultSet that was from archaic Django. Removed apparently due to compatibility issues
2020-08-10 16:49:46 -04:00

86 lines
2.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.conf import settings
from django.contrib.postgres.fields import (
ArrayField, HStoreField,
IntegerRangeField, DateRangeField,
DateTimeRangeField)
from django.db.models import (
Model, CharField, ForeignKey, BooleanField, DateField, DateTimeField,
ManyToManyField, BinaryField, IntegerField, GenericIPAddressField,
FloatField, DecimalField, DurationField, UUIDField, SET_NULL, PROTECT)
class Test(Model):
name = CharField(max_length=20)
owner = ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True,
on_delete=SET_NULL)
public = BooleanField(default=False)
date = DateField(null=True, blank=True)
datetime = DateTimeField(null=True, blank=True)
permission = ForeignKey('auth.Permission', null=True, blank=True,
on_delete=PROTECT)
# We cant use the exact names `float` or `decimal` as database column name
# since it fails on MySQL.
a_float = FloatField(null=True, blank=True)
a_decimal = DecimalField(null=True, blank=True,
max_digits=5, decimal_places=2)
bin = BinaryField(null=True, blank=True)
ip = GenericIPAddressField(null=True, blank=True)
duration = DurationField(null=True, blank=True)
uuid = UUIDField(null=True, blank=True)
try:
from django.db.models import JSONField
json = JSONField(null=True, blank=True)
except ImportError:
pass
class Meta:
ordering = ('name',)
class TestParent(Model):
name = CharField(max_length=20)
class TestChild(TestParent):
public = BooleanField(default=False)
permissions = ManyToManyField('auth.Permission', blank=True)
class PostgresModel(Model):
int_array = ArrayField(IntegerField(null=True, blank=True), size=3,
null=True, blank=True)
hstore = HStoreField(null=True, blank=True)
try:
from django.contrib.postgres.fields import JSONField
json = JSONField(null=True, blank=True)
except ImportError:
pass
int_range = IntegerRangeField(null=True, blank=True)
try:
from django.contrib.postgres.fields import FloatRangeField
float_range = FloatRangeField(null=True, blank=True)
except ImportError:
pass
try:
from django.contrib.postgres.fields import DecimalRangeField
decimal_range = DecimalRangeField(null=True, blank=True)
except ImportError:
pass
date_range = DateRangeField(null=True, blank=True)
datetime_range = DateTimeRangeField(null=True, blank=True)
class Meta:
# Tests schema name in table name.
db_table = '"public"."cachalot_postgresmodel"'
class UnmanagedModel(Model):
name = CharField(max_length=50)
class Meta:
managed = False