1+ import traceback
2+
3+ import django
14from django .db .models import Field , JSONField
25from django .forms import Textarea
36
47from django_editorjs .widgets import EditorJsWidget
58
9+ from .config import DEBUG
10+
11+ NEW_VERSION = False
12+
13+ if django .VERSION [0 ] == 3 and django .VERSION [1 ] >= 1 :
14+ NEW_VERSION = True
15+
16+
17+ class FieldMixin (Field ):
18+ def get_internal_type (self ):
19+ return "TextField"
20+
621
722class EditorJsFieldMixin :
8- def __init__ (self , * args , plugins = None , tools = None , ** kwargs ):
23+ def __init__ (self , plugins = None , tools = None , ** kwargs ):
924 self .plugins = plugins
1025 self .tools = tools
1126 self .version = kwargs .pop ('version' , '2.18.0' )
1227 self .use_editor_js = kwargs .pop ('use_editor_js' , True )
13- super ().__init__ (* args , * *kwargs )
28+ super ().__init__ (** kwargs )
1429
1530 def formfield (self , ** kwargs ):
1631 if self .use_editor_js :
@@ -26,10 +41,21 @@ def formfield(self, **kwargs):
2641 return super ().formfield (** defaults )
2742
2843
29- class EditorJsTextField (EditorJsFieldMixin , Field ):
30- def get_internal_type (self ):
31- return "TextField"
32-
33-
34- class EditorJsJSONField (EditorJsFieldMixin , JSONField ):
35- pass
44+ class EditorJsTextField (EditorJsFieldMixin , FieldMixin ):
45+ def __init__ (self , plugins = None , tools = None , ** kwargs ):
46+ super ().__init__ (plugins , tools , ** kwargs )
47+
48+
49+ class EditorJsJSONField (EditorJsFieldMixin , JSONField if NEW_VERSION else FieldMixin ):
50+ def __init__ (self , plugins = None , tools = None , ** kwargs ):
51+ if not NEW_VERSION and DEBUG :
52+ print ()
53+ print ('\x1b [0;30;43m {}\x1b [0m' .format (
54+ 'Warning: you don\' t support JSONField, ' +
55+ 'please use EditorJsTextField instead of EditorJsJSONField'
56+ ))
57+ print ('\x1b [2;34;93m{}\x1b [0m' .format (
58+ traceback .format_stack ()[- 3 :][0 ]
59+ ))
60+ print ()
61+ super ().__init__ (plugins , tools , ** kwargs )
0 commit comments