Django - Save html data into a quillfield

32 Views Asked by At

I have a model Product as below:

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 am getting an error: can't parse value

1

There are 1 best solutions below

0
willeM_ Van Onsem On BEST ANSWER

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()