Questions tagged [django-jsonfield]

162 questions
53
votes
1 answer

How to perform filtering with a Django JSONField?

I'm using PostgreSQL and this new field from Django 1.9, JSONField. So I got the following data: id|data 1 |[{'animal': 'cat', 'name': 'tom'}, {'animal': 'dog', 'name': 'jerry'}, {'animal': 'dog', 'name': 'garfield'}] I'm trying to figure out how…
ezdookie
  • 1,477
  • 3
  • 15
  • 19
25
votes
7 answers

Django Admin: JSONField default empty dict wont save in admin

in my model defn i have from django.contrib.postgres.fields import JSONField ..... ....... ......... media_data=JSONField(default=dict) I created a default admin When i attempt to save without touching the field, i get a this field is required…
w--
  • 6,427
  • 12
  • 54
  • 92
21
votes
3 answers

Django filter JSONField list of dicts

I run Django 1.9 with the new JSONField and have the following Test model : class Test(TimeStampedModel): actions = JSONField() Let's say the action JSONField looks like this : [ { "fixed_key_1": "foo1", "fixed_key_2": { …
18
votes
7 answers

Django 1.9 JSONField order_by

I have the following django model that contains JSONField: class RatebookDataEntry(models.Model): data = JSONField(blank=True, default=[]) last_update = models.DateTimeField(auto_now=True) class Meta: verbose_name_plural =…
ryche
  • 2,004
  • 2
  • 18
  • 27
11
votes
3 answers

django object is not JSON serializable error after upgrading django to 1.6.5

I have a django app which was running on 1.4.2 version and working completely fine, but recently i updated it to django 1.6.5 and facing some wierd errors like below Actually i am getting this during user/client registration process in my site…
Shiva Krishna Bavandla
  • 25,548
  • 75
  • 193
  • 313
10
votes
1 answer

Django Json field filter throws lookup error

I am using django postgres JSONfield and the model structure is as below from django.contrib.postgres.fields import JSONField class JsonAnswer(models.Model): name = models.CharField(max_length=255) data = JSONField(default={}) the data…
Mallik Sai
  • 186
  • 1
  • 4
  • 16
10
votes
1 answer

Django JSONField isnull lookup

As far as I know you can't use __isnull lookups on django native JSONField. On the Internet I found this inactive issue. As possible workaround we can of course use these hacks: model.objects.filter(field__contains={'key': None}), which isn't so…
valignatev
  • 6,020
  • 8
  • 37
  • 61
9
votes
2 answers

django.db.utils.ProgrammingError: cannot cast type text[] to jsonb

I was trying to include JSONField in my model: from django.contrib.postgres.fields import JSONField class Trigger(models.Model): solutions = JSONField(blank=True, null=True) However, when I try to migrate the database, it gives the following…
8
votes
1 answer

Django annotate count in JSONField with Postgres

Using Django I have a field which is of type JSONField. I am wanting to get a distinct count on a nested key/value in the json. With a normal field you can just do soemthing like the following …
ms18
  • 335
  • 1
  • 3
  • 11
8
votes
4 answers

Query by empty JsonField in django

I need to query a model by a JsonField, I want to get all records that have empty value ([]): I used MyModel.objects.filter(myjsonfield=[]) but it's not working, it returns 0 result though there's records having myjsonfield=[]
mou55
  • 660
  • 1
  • 8
  • 13
7
votes
1 answer

How to preserve key order in a Django JSONField

I am having a hard time preserving the order of keys in a JSON object stored in a Django JSONField. I have tried using a custom encoder and decoder as per the docs, but the JSON object keeps re-ordeing itself: >>>from models import…
trubliphone
  • 4,132
  • 3
  • 42
  • 66
7
votes
2 answers

django - Unsupported lookup for JSONField or join on the field not permitted

I am having a Json field in my models as - class Product(models.Model): ... detailed_stock = JSONField(load_kwargs={'object_pairs_hook': collections.OrderedDict},default=dict) I am having values in my database like - { …
7
votes
1 answer

How to test postgresql specific feature such as JsonField in Django?

I would like to use Postgresql specific JSONField in Django, however, I have not found a way to test with sqlite environment. Any tip for elegant way?
Jun
  • 351
  • 3
  • 13
7
votes
1 answer

How can i get values of JSONfield in my template

I tried to find the answer but couldn't. In my template when I iterate over JSONfield {% extends "electronic/electronic_base.html" %} {% load staticfiles %} {% block content %} {% for item in micro_all %}

{{item.title}}

Valery Lukin
  • 85
  • 2
  • 5
7
votes
1 answer

JsonEditor integration with Django Admin

I am working on integrating JSONEditor into the Django admin. There is one field in my model that uses the Postgres JSON and the Tree editor in this library is perfect. models.py class Executable(models.Model): """ Simplified model for sake…
1
2 3
10 11