Skip to content

Commit

Permalink
rewrite QuillField to inherit JSONField (#27)
Browse files Browse the repository at this point in the history
this allows the db backend to apply any optimizations it might want/need
closes #26

Co-authored-by: proxi <[email protected]>
  • Loading branch information
proxi and proxi authored Feb 9, 2021
1 parent 76e6e72 commit a362dca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion django_quill/fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from django.db import models

from .forms import QuillFormField
Expand Down Expand Up @@ -31,7 +33,7 @@ def _require_quill(self):

def _get_quill(self):
self._require_quill()
self._quill = Quill(self.json_string)
self._quill = Quill(json.loads(self.json_string))
return self._quill

def _set_quill(self, quill):
Expand Down
5 changes: 4 additions & 1 deletion django_quill/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
)


class QuillFormField(forms.fields.CharField):
class QuillFormField(forms.fields.JSONField):
def __init__(self, *args, **kwargs):
kwargs.update({
'widget': QuillWidget(),
})
super().__init__(*args, **kwargs)

def prepare_value(self, value):
return value.json_string
7 changes: 3 additions & 4 deletions django_quill/quill.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from json import JSONDecodeError

__all__ = (
'QuillParseError',
Expand All @@ -18,9 +17,9 @@ def __str__(self):
class Quill:
def __init__(self, json_string):
try:
self.json_string = json_string
json_data = json.loads(json_string)
self.json_string = json.dumps(json_string)
json_data = json_string
self.delta = json_data['delta']
self.html = json_data['html']
except (JSONDecodeError, KeyError, TypeError):
except (json.JSONDecodeError, KeyError, TypeError):
raise QuillParseError(json_string)

0 comments on commit a362dca

Please sign in to comment.