How I can insert json
values that I am getting from request.get("some url")
into database in django?
Asked
Active
Viewed 57 times
0

Pradip Kachhadiya
- 2,067
- 10
- 28

sqty87
- 1
- 1
-
You could use [a JSON field](https://github.com/derek-schaefer/django-json-field) – Nils Werner Mar 28 '21 at 16:37
-
`request.get("some url").json()` – Pedro Lobito Mar 28 '21 at 16:52
-
Does this answer your question? [Django 1.9 - JSONField in Models](https://stackoverflow.com/questions/37007109/django-1-9-jsonfield-in-models) – Swetank Poddar Mar 28 '21 at 17:34
1 Answers
0
You can use django-json-field or insert json
data in TextField
.
For ex.
models.py:
import json
class MyModel(models.Model):
...
other_detail = models.TextField(default="{}")
@property
def other_detail_json(self):
return json.loads(self.other_detail)
views.py:
# Insert JSON data
...
data = request.get("some url")
other_details = json.dumps(data)
MyModel.objects.create(other_detail = other_details,...)
#fetch JSON data
obj = MyModel.objects.get(id = id)
other_detail = obj.other_detail_json
print(other_detail)

Pradip Kachhadiya
- 2,067
- 10
- 28