1- from django .db .models import Field , JSONField
1+ import traceback
2+
3+ import django
4+ from django .db .models import Field
25from django .forms import Textarea
36
47from django_editorjs .widgets import EditorJsWidget
58
9+ from .config import DEBUG
10+
11+ try :
12+ # pylint: disable=ungrouped-imports
13+ from django .db .models import JSONField
14+ except ImportError :
15+ pass
16+
17+ NEW_VERSION = False
18+
19+ if django .VERSION [0 ] == 3 and django .VERSION [1 ] >= 1 :
20+ NEW_VERSION = True
21+
22+
23+ class FieldMixin (Field ):
24+ def get_internal_type (self ):
25+ return "TextField"
26+
627
728class EditorJsFieldMixin :
8- def __init__ (self , * args , plugins = None , tools = None , ** kwargs ):
29+ def __init__ (self , plugins = None , tools = None , ** kwargs ):
930 self .plugins = plugins
1031 self .tools = tools
1132 self .version = kwargs .pop ('version' , '2.18.0' )
1233 self .use_editor_js = kwargs .pop ('use_editor_js' , True )
13- super ().__init__ (* args , * *kwargs )
34+ super ().__init__ (** kwargs )
1435
1536 def formfield (self , ** kwargs ):
1637 if self .use_editor_js :
@@ -26,10 +47,21 @@ def formfield(self, **kwargs):
2647 return super ().formfield (** defaults )
2748
2849
29- class EditorJsTextField (EditorJsFieldMixin , Field ):
30- def get_internal_type (self ):
31- return "TextField"
50+ class EditorJsTextField (EditorJsFieldMixin , FieldMixin ):
51+ def __init__ (self , plugins = None , tools = None , ** kwargs ):
52+ super (). __init__ ( plugins , tools , ** kwargs )
3253
3354
34- class EditorJsJSONField (EditorJsFieldMixin , JSONField ):
35- pass
55+ class EditorJsJSONField (EditorJsFieldMixin , JSONField if NEW_VERSION else FieldMixin ):
56+ def __init__ (self , plugins = None , tools = None , ** kwargs ):
57+ if not NEW_VERSION and DEBUG :
58+ print ()
59+ print ('\x1b [0;30;43m {}\x1b [0m' .format (
60+ 'Warning: you don\' t support JSONField, ' +
61+ 'please use EditorJsTextField instead of EditorJsJSONField'
62+ ))
63+ print ('\x1b [2;34;93m{}\x1b [0m' .format (
64+ traceback .format_stack ()[- 3 :][0 ]
65+ ))
66+ print ()
67+ super ().__init__ (plugins , tools , ** kwargs )
0 commit comments