How to import csv or json file into the model & create taboe for that data

I've a csv/json file. I need to include the file as a database for the django app. & I need to show the data as a table in frontend. So can't understand where I should insert the file so that it create table for me.

I've create a django web application. With a app. Just trying to import file intothe model but in dbsqlite there is no change.

This is a code that reads data from a csv file and loads it to a product database table it saves the product title, description and price Try this:

import csv

from .models import Product


def run(file):

    open = open(file)
    read = csv.reader(open)

    Product.objects.all().delete()

    for row in read:

    product = Product.create(product=row[0],description=row[1],price=row[2])
    product. Save()

if you are reading from a file change the code to this

def run():
    open = open('[link to your file]')
    read = csv.reader(open)

    Product.objects.all().delete()

    for row in read:

    product = Product.create(product=row[0],description=row[1],price=row[2])
    product. Save()
Back to Top