11
11
from django .db .models .related import RelatedObject
12
12
from django .conf import settings
13
13
from django .contrib import admin
14
- from django .utils import importlib
14
+ from django .utils import importlib , six
15
+ from django .utils .encoding import python_2_unicode_compatible
15
16
try :
16
17
from django .utils .encoding import smart_text
17
18
except ImportError :
18
- smart_text = unicode
19
- try :
20
- from django .utils .six import text_type
21
- except ImportError :
22
- text_type = unicode
19
+ from django .utils .encoding import smart_unicode as smart_text
23
20
try :
24
21
from django .utils .timezone import now
25
22
except ImportError :
28
25
from django .utils .translation import string_concat
29
26
from .manager import HistoryDescriptor
30
27
31
- try :
32
- basestring
33
- except NameError :
34
- basestring = str # Python 3 has no basestring
35
-
36
- try :
37
- from django .utils .encoding import python_2_unicode_compatible
38
- except ImportError : # django 1.3 compatibility
39
- import sys
40
-
41
- # copy of django function without use of six
42
- def python_2_unicode_compatible (klass ):
43
- """
44
- Decorator defining __unicode__ and __str__ as appropriate for Py2/3
45
-
46
- Usage: define __str__ method and apply this decorator to the class.
47
- """
48
- if sys .version_info [0 ] != 3 :
49
- klass .__unicode__ = klass .__str__
50
- klass .__str__ = lambda self : self .__unicode__ ().encode ('utf-8' )
51
- return klass
52
-
53
-
54
28
registered_models = {}
55
29
56
30
@@ -62,7 +36,7 @@ def __init__(self, verbose_name=None, bases=(models.Model,),
62
36
self .user_set_verbose_name = verbose_name
63
37
self .user_related_name = user_related_name
64
38
try :
65
- if isinstance (bases , basestring ):
39
+ if isinstance (bases , six . string_types ):
66
40
raise TypeError
67
41
self .bases = tuple (bases )
68
42
except TypeError :
@@ -254,7 +228,7 @@ def get_one_to_one_field(self, to_field, other):
254
228
# recursive
255
229
temp_field = self .__class__ (to_field .rel .to ._meta .object_name )
256
230
for key , val in to_field .__dict__ .items ():
257
- if (isinstance (key , basestring )
231
+ if (isinstance (key , six . string_types )
258
232
and not key .startswith ('_' )):
259
233
setattr (temp_field , key , val )
260
234
field = self .__class__ .get_field (
@@ -295,7 +269,7 @@ def get_field(self, other, cls):
295
269
"blank" ,
296
270
)
297
271
for key , val in to_field .__dict__ .items ():
298
- if (isinstance (key , basestring )
272
+ if (isinstance (key , six . string_types )
299
273
and not key .startswith (excluded_prefixes )
300
274
and key not in excluded_attributes ):
301
275
setattr (field , key , val )
0 commit comments