Django - Save html data into a quillfield

I have a model

 class Product(models.Model): 
description = QuillField(null=True, blank=True)

In django views how can I save html data in it ?

product = Product.objects.get(id=...) 
product.description = '<p> this is a test </p>'
product.save()

but I have an error: can't parse value

You need to wrap the content in a JSON blob, so:

import json

product = Product.objects.get(id=…)
product.description = json.dumps(
    {
        'delta': {'ops': []},
        'html': '<p> this is a test </p>',
    }
)
product.save()
Back to Top