0

I am having a Django model like:

class Subscription(models.Model):
    data = JSONField(default=dict)

I want to do something like this:

data = {"product_id": 123, "available": False}
subscription, new = Subscription.objects.get_or_create(data__product_id=123, 
data__available=False)

I tried doing the above but it just set the field as empty dictionary.

Shashank
  • 834
  • 1
  • 9
  • 13

1 Answers1

0

Try this:-

models.py :-
class Subscription(models.Model):
    data = JSONField(db_index=True,null=True)

views.py:-
DictToStore = {"product_id": 123, "available": False}
subscription, new = Subscription.objects.get_or_create(data=DictToStore)
Piyush S. Wanare
  • 4,703
  • 6
  • 37
  • 54