-
Notifications
You must be signed in to change notification settings - Fork 146
/
models.py
67 lines (50 loc) · 2.24 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from django.conf import settings
from django.contrib.postgres.fields import (
ArrayField, HStoreField,
IntegerRangeField, JSONField, FloatRangeField, 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 can’t 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)
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)
json = JSONField(null=True, blank=True)
int_range = IntegerRangeField(null=True, blank=True)
float_range = FloatRangeField(null=True, blank=True)
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