Sometimes, we want to store a dictionary on a Python Django Model.
In this article, we’ll look at how to store a dictionary on a Python Django Model.
How to store a dictionary on a Python Django Model?
To store a dictionary on a Python Django Model, we can create a JSONField
with the jsonfield
package.
To install it, we run
pip install jsonfield
to install it.
Then we write
from django.db import models
from jsonfield import JSONField
class MyModel(models.Model):
json = JSONField()
to create the json
JSONField
in MyModel
to create the JSON field.
Conclusion
To store a dictionary on a Python Django Model, we can create a JSONField
with the jsonfield
package.