Django JSON field. 'module' object has no attribute 'JSONField'
There's no JSONField
in models
module, you need to:
from django.contrib.postgres.fields import JSONField
class Question(models.Model):
question_text = JSONField()
Django doc about JSONField.
Django 3.1 update
Starting with Django 3.1, the JSONField
is now available for all database backends.
https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.JSONField
There's no JSONField
in models. But there's a handy jsonfield
package available to use JSONField
in Django models. To install the package, do:
pip install jsonfield
Once installed, do:
from jsonfield import JSONField
from django.db import models
class Question(models.Model):
question_text = JSONField(max_length=200)
pub_date = models.DateTimeField('date published')