Answers for "django json field"

0

django json field

# New version
class MyModel(models.Model):
  attribute = models.JSONField(...)

  
  
# Old version (<3.1, Postgres only)
from django.contrib.postgres.fields import JSONField

class MyModel(models.Model):
  attribute = JSONField(...)
Posted by: Guest on July-18-2021
0

jsonfield django

>>> Dog.objects.create(name='Rufus', data={
...     'breed': 'labrador',
...     'owner': {
...         'name': 'Bob',
...         'other_pets': [{
...             'name': 'Fishy',
...         }],
...     },
... })
>>> Dog.objects.create(name='Meg', data={'breed': 'collie', 'owner': None})

>>> Dog.objects.filter(data__breed='collie')
<QuerySet [<Dog: Meg>]>
Posted by: Guest on September-03-2020

Python Answers by Framework

Browse Popular Code Answers by Language