forked from gregmuellegger/django-autofixture
/
models.py
109 lines (75 loc) · 3.21 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
import os
from datetime import datetime
from django.db import models
filepath = os.path.dirname(os.path.abspath(__file__))
def y2k():
return datetime(2000, 1, 1)
class SimpleModel(models.Model):
name = models.CharField(max_length=50)
class OtherSimpleModel(models.Model):
name = models.CharField(max_length=50)
class DeepLinkModel1(models.Model):
related = models.ForeignKey('SimpleModel')
related2 = models.ForeignKey('SimpleModel',
related_name='deeplinkmodel1_rel2',
null=True, blank=True)
class DeepLinkModel2(models.Model):
related = models.ForeignKey('DeepLinkModel1')
class NullableFKModel(models.Model):
m2m = models.ManyToManyField('SimpleModel', null=True, blank=True)
class BasicModel(models.Model):
chars = models.CharField(max_length=50)
shortchars = models.CharField(max_length=2)
blankchars = models.CharField(max_length=100, blank=True)
nullchars = models.CharField(max_length=100, blank=True, null=True)
slugfield = models.SlugField()
textfield = models.TextField()
defaultint = models.IntegerField(default=1)
intfield = models.IntegerField()
pintfield = models.PositiveIntegerField()
sintfield = models.SmallIntegerField()
psintfield = models.PositiveSmallIntegerField()
STRING_CHOICES = (
('a', 'A'),
('b', 'B'),
('c', 'C'),
)
choicefield = models.CharField(choices=STRING_CHOICES, max_length=1)
datefield = models.DateField()
datetimefield = models.DateTimeField()
defaultdatetime = models.DateTimeField(default=y2k)
timefield = models.TimeField()
decimalfield = models.DecimalField(max_digits=10, decimal_places=4)
emailfield = models.EmailField()
ipaddressfield = models.IPAddressField()
urlfield = models.URLField()
rfilepathfield = models.FilePathField(path=filepath, recursive=True)
filepathfield = models.FilePathField(path=filepath)
mfilepathfield = models.FilePathField(path=filepath, match=r'^.+\.py$')
class UniqueTestModel(models.Model):
CHOICES = [(i,i) for i in range(10)]
choice1 = models.PositiveIntegerField(choices=CHOICES, unique=True)
class UniqueTogetherTestModel(models.Model):
CHOICES = [(i,i) for i in range(10)]
choice1 = models.PositiveIntegerField(choices=CHOICES)
choice2 = models.PositiveIntegerField(choices=CHOICES)
class Meta:
unique_together = ('choice1', 'choice2')
class RelatedModel(models.Model):
related = models.ForeignKey(BasicModel, related_name='rel1')
limitedfk = models.ForeignKey(SimpleModel,
limit_choices_to={'name__exact': 'foo'}, related_name='rel2',
null=True, blank=True)
class O2OModel(models.Model):
o2o = models.OneToOneField(SimpleModel)
class M2MModel(models.Model):
m2m = models.ManyToManyField(SimpleModel, related_name='m2m_rel1')
secondm2m = models.ManyToManyField(OtherSimpleModel, related_name='m2m_rel2',
null=True, blank=True)
class ThroughModel(models.Model):
simple = models.ForeignKey('SimpleModel')
other = models.ForeignKey('M2MModelThrough')
class M2MModelThrough(models.Model):
m2m = models.ManyToManyField(SimpleModel, related_name='m2mthrough_rel1',
through=ThroughModel)