0

My Model:

class Post_Data(models.Model):
    id = models.AutoField(primary_key=True)
    data = models.CharField(max_length=200)

I need to insert the json data inside the model which will be passed in the form of "file" in postman.

I tried:

    def post(self, request):
        json_file = request.FILES['json_file']
        with open(json_file) as f:
            json_data = json.loads(f)
            a = Post_data(data=json_data)
            a.save()

But it's not working.

Zodiac
  • 121
  • 1
  • 9

1 Answers1

0

Have you looked at Django Fixtures for prepopulating of data. Additionally using JsonField() might be useful to you.

from django.contrib.postgres.fields import JSONField

class ......
    data = JSONField()
DARK_C0D3R
  • 2,075
  • 16
  • 21