Got this load_data.py file to import a csv data to a django model table...but it's not working, in terminal as i execute command "python3 ./load_data.py" it just goes to the same line as if load.py weren't even called like this:
(cost_control_local) juanda@juanda-VirtualBox:~/cost_control_repository/cost_control/csv_data$ python3 ./load_data.py
(cost_control_local) juanda@juanda-VirtualBox:~/cost_control_repository/cost_control/csv_data$
this is the load_data.py code :
import csv,sys,os
import django
pathproject = "/home/juanda/cost_control_repository/cost_control"
base_csv_filepath = "/home/juanda/cost_control_repository/cost_control/csv_data"
sys.path.append(pathproject)
os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings.local'
django.setup()
from cost_control_app.models import Suppliers
def load_suppliers():
print ("Entering...")
csv_file = base_csv_filepath + "supplier_data.csv"
dataReader = csv.reader(open(csv_file, encoding='utf-8'),delimiter=',',quotechar='"')
#dataReader = csv.reader(open(csv_file), delimiter=',', quotechar='"')
for row in dataReader:
if row[0] != 'ID':
Suppliers.objects.create(
supplier=row[0],
supplier_description=row[1]
)
print ("Imported correctly")
Any ideas ? thanks for your help !!