Open Hiradoras opened 2 years ago
me also fetch this type of problem
I had the same problem so I dug through the code and it seems you can serialize it by calling the property html
and plain
(there's also delta
but I'm not sure what it does). See their code at django_quill.fields
class FieldQuill
.
Here's my working DRF serializer
class ConsentSerializer(serializers.ModelSerializer):
html = serializers.SerializerMethodField()
plain = serializers.SerializerMethodField()
def get_html(self, instance):
return str(instance.body.html)
def get_plain(self, instance):
return str(instance.body.plain)
class Meta:
model = Consent
fields = ["id", "name", "html", "plain"]
The above didn't worked for me but this did
class FieldQuillSerializer(serializers.Field):
def to_representation(self, value):
# Assuming `value` is an instance of your FieldQuill class
return {
'json_string': value.json_string,
'html': value.html,
'delta': value.delta,
'plain': value.plain,
}
def to_internal_value(self, data):
pass
class ContentSerializer(serializers.ModelSerializer):
heading = FieldQuillSerializer()
description = FieldQuillSerializer()
class Meta:
model = Content
fields = ["heading","description"]
I'm trying to access my Post model's content, which is QuillField(). in views.py I have: post_words = post.content But content's type is QuillField, so I get this <django_quill.fields.FieldQuill object at 0x000001958CAD5C30> Is there any way to convert this to plain text in views, so I can count how many words in post?