3
3
4
4
from django .core .exceptions import ValidationError
5
5
from django .db import models
6
- from django .utils .encoding import python_2_unicode_compatible
7
6
8
7
9
- @python_2_unicode_compatible
10
8
class Author (models .Model ):
11
9
name = models .CharField (max_length = 100 )
12
10
birthday = models .DateTimeField (auto_now_add = True )
@@ -24,7 +22,6 @@ def full_clean(self, exclude=None, validate_unique=True):
24
22
raise ValidationError ({'name' : "'123' is not a valid value" })
25
23
26
24
27
- @python_2_unicode_compatible
28
25
class Category (models .Model ):
29
26
name = models .CharField (
30
27
max_length = 100 ,
@@ -35,7 +32,6 @@ def __str__(self):
35
32
return self .name
36
33
37
34
38
- @python_2_unicode_compatible
39
35
class Book (models .Model ):
40
36
name = models .CharField ('Book name' , max_length = 100 )
41
37
author = models .ForeignKey (Author , blank = True , null = True , on_delete = models .CASCADE )
@@ -51,15 +47,13 @@ def __str__(self):
51
47
return self .name
52
48
53
49
54
- @python_2_unicode_compatible
55
50
class Parent (models .Model ):
56
51
name = models .CharField (max_length = 100 )
57
52
58
53
def __str__ (self ):
59
54
return self .name
60
55
61
56
62
- @python_2_unicode_compatible
63
57
class Child (models .Model ):
64
58
parent = models .ForeignKey (Parent , on_delete = models .CASCADE )
65
59
name = models .CharField (max_length = 100 )
@@ -89,10 +83,12 @@ class WithDefault(models.Model):
89
83
name = models .CharField ('Default' , max_length = 75 , blank = True ,
90
84
default = 'foo_bar' )
91
85
86
+
92
87
def random_name ():
93
88
chars = string .ascii_lowercase
94
89
return '' .join (random .SystemRandom ().choice (chars ) for _ in range (100 ))
95
90
91
+
96
92
class WithDynamicDefault (models .Model ):
97
93
98
94
name = models .CharField ('Dyn Default' , max_length = 100 ,
0 commit comments