-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add QuillHtmlField and QuillPlainField to integrate with DRF
- Loading branch information
1 parent
5c13798
commit 7ba2e65
Showing
15 changed files
with
140 additions
and
4 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from rest_framework import serializers | ||
|
||
from django_quill.fields import FieldQuill | ||
|
||
__all__ = ( | ||
"QuillFieldMixin", | ||
"QuillHtmlField", | ||
"QuillPlainField", | ||
) | ||
|
||
|
||
class QuillFieldMixin: | ||
pass | ||
|
||
|
||
class QuillHtmlField(QuillFieldMixin, serializers.Field): | ||
def to_representation(self, value: FieldQuill): | ||
return value.quill.html | ||
|
||
|
||
class QuillPlainField(QuillFieldMixin, serializers.Field): | ||
def to_representation(self, value: FieldQuill): | ||
return value.quill.plain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Integration with DRF | ||
|
||
## Serializer Fields | ||
|
||
- `django_quill.drf.fields.QuillHtmlField` | ||
HTML content of QuillField | ||
- `django_quill.drf.fields.QuillPlainField` | ||
Plain text of QuillField | ||
|
||
example: | ||
|
||
**models.py** | ||
|
||
```python | ||
from django_quill.fields import QuillField | ||
|
||
class QuillPost(models.Model): | ||
content = QuillField() | ||
``` | ||
|
||
**serializers.py** | ||
|
||
```python | ||
from rest_framework import serializers | ||
from django_quill.drf.fields import QuillHtmlField, QuillPlainField | ||
from posts.models import QuillPost | ||
|
||
class QuillPostSerializer(serializers.ModelSerializer): | ||
content = QuillHtmlField() | ||
content_plain = QuillPlainField(source='content') | ||
|
||
class Meta: | ||
model = QuillPost | ||
fields = "__all__" | ||
|
||
``` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from rest_framework import viewsets | ||
|
||
from posts.models import QuillPost | ||
from posts.serializers import QuillPostSerializer | ||
|
||
__all__ = ("QuillPostViewSet",) | ||
|
||
|
||
class QuillPostViewSet(viewsets.ModelViewSet): | ||
queryset = QuillPost.objects.all() | ||
serializer_class = QuillPostSerializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from rest_framework import serializers | ||
|
||
from django_quill.drf.fields import QuillHtmlField, QuillPlainField | ||
from posts.models import QuillPost | ||
|
||
__all__ = ("QuillPostSerializer",) | ||
|
||
|
||
class QuillPostSerializer(serializers.ModelSerializer): | ||
content = QuillHtmlField() | ||
content_plain = QuillPlainField(source="content") | ||
|
||
class Meta: | ||
model = QuillPost | ||
fields = "__all__" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.33 | ||
0.1.34 |