15👍
✅
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')
25👍
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.
- Constantly send data to client from server
- Creating custom Exceptions that Django reacts to
- Geo Django get cities from latitude and longitude
19👍
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
- Failed to start gunicorn.service: Unit gunicorn.service not found
- How to see exception generated into django template variable?
1👍
Changing the import statement should fix your problem (it helped me):
from django.contrib.postgres.fields.jsonb import JSONField
So JSONField is located in jsonb module now.
Source:stackexchange.com