4👍
Customer.objects.filter(data__contains={'key1': 'text1'})
The returned objects are those where the given dict of key-value pairs are all contained in the field.
- Active Django settings file from Celery worker
- Set default value for dropdown in django forms
- Use slugify in template
- How do I write a Django model with ManyToMany relationsship with self through a Model
3👍
JSONField in Django is saved with json.dumps()
You can try:
import json
search = json.dumps({'key1': 'text1'})[1:-1] # removed { and }
Customer.objects.filter(data__contains=search)
If this code fail, you can try the next:
search = '"key1":"text1"'
Customer.objects.filter(data__contains=search)
- What clears the lock created by select_for_update in Django?
- AttributeError: 'RelatedManager' object has no attribute 'remove'
- PyTest-Django Failing on missing django_migration table
- Revert migration on deleted not null field
- Add `help_text` to Django Admin field
Source:stackexchange.com