Questions tagged [django-jsonfield]

162 questions
1
vote
1 answer

Type Validation in Django's JSONField

Problem Statement I have a Django model containing a JSONField among other fields: class MetaData(models.Model): main = models.ForeignKey() name = models.CharField() dict_field = models.JSONField() Where dict_field is a "data dump"…
1
vote
0 answers

Update values in jsonfield for particular keys

I have JSONField in my model with following structure: { "1": { ... "is_disabled": false }, "2": { ... "is_disabled": false }, "3": { …
hungry7
  • 49
  • 1
  • 4
1
vote
0 answers

How to Updating JSONField in Django?

I'll give coffee to the person who found the solution Help me please. Query object:The result I want is just to update the value of auth_token My model: class Student(models.Model): name = models.CharField(max_length=100, null=True,…
Batgerel
  • 11
  • 1
1
vote
1 answer

Django get TypeError: the JSON object must be str, bytes or bytearray, not dict

I'm saving a dict into a JSONfield field in my model. This is going ok, but when I want to retrieve data by id, the next error message appears: ***TypeError: the JSON object must be str, bytes or bytearray, not dict This is an example of what I'm…
eduardosufan
  • 1,441
  • 2
  • 23
  • 51
1
vote
3 answers

Django FilterSet for JSON fields

For example, I have a simple django-model: class SimpleModel(models.Model): some_attr = models.JSONField() #there is [attr1, attr2, ...] in JSON Simple view: class SimpleView(ListCreateApivView): filter_backends = [DjangoFilterBackend, ] …
1
vote
2 answers

How to get the json key and value in Django's Templating language?

I'm trying to build a website for tv series using Django framework, I put in the models.py all kinds of details about that show and a JSONField to define the number seasons and episodes in each season. Example: { "s1" : 15 , "s2" : 25 , "s3" : 23} I…
1
vote
3 answers

How can I receive a list of dictionaries in djano?

Hello I am working on a djago project and I want to recieve a list of dictionaries just like this: [{1: 20}, {2:30}, {3: 50}, ......] here the key is the id of the productand value is price And the code below is just receiving a single dictionary…
1
vote
1 answer

django.db.utils.IntegrityError: UNIQUE constraint failed: store_wishlist.user_id

I am working on ecommerce website. I wanted to implement wishlist function on my website. And, it is working if its the first time for user that is adding to the list. In the second time giving an error. What's the problem? Can someone please help…
1
vote
1 answer

Unable to save to model with JSONField

I've been at this problem for so long that I'm not even sure where I am with it. I've written the following management command which generates some JSON and saves it using a Django model. Later I have a view which retrieves this JSON and displays it…
rcx935
  • 217
  • 5
  • 15
1
vote
1 answer

How to query and update nested JSON data in Django

I have below class defined to do statistics for voting system. class FormPage(AbstractForm): submission_stats = models.JSONField(null=True, editable=False) Now, I have submission_stats in below format: [ { "id":4, …
Yan Tian
  • 377
  • 3
  • 11
1
vote
0 answers

Updating Django's JSONField

Let's say I have a model: class Foo(Model): bar = JSONField(...) I can easily filter by the elements of bar. For example, Foo.objects.filter(bar__has_key="some_key").count() will give me the number of Foo objects that have "some_key" as a key…
Vedran Šego
  • 3,553
  • 3
  • 27
  • 40
1
vote
1 answer

How to show Json data to Django template?

I store JSON data to TextField : Data in TextField: [{"id":1,"Name":"AC","Quantity":"12","Weight":"200","WeightTypes":"KG", "TotalWeight":"2400","CustomsCharge":"300.0","Subtotal":"3600"}, {"id":2,"Name":"Soap","Quantity":"12","Weight":"500", …
1
vote
2 answers

JSON data saving using Django 3.3

As we know, Django=3 is supporting JSONField . I am trying to save JSON data in my Django Project using JavaScript, i have take data in a input field which looks like: [{"id":1,"Name":"Antenna","Pieces":"","Weight":"","Weight…
1
vote
1 answer

Django Model save() retains mutable reference for JSONFields()

# Model contains only one JSON field class TestModel(models.Model): field = JSONField(default=dict) # Dictionary, assigned to model.field field_json = {"test": 5} model = TestModel(field = field_json) model.save() # Returns true.…
1
vote
0 answers

DRF Update Json Field Value in queryset

I was trying to update the json field but I couldn't update it because it throw me an exception. I'm using Django 2.6 class Mymodel(models.Model): qty = models.IntegerField(default=0) name = models.CharField(max_length=255) description =…