Hi there… I have more them 20k record to auto import when I install the application… using fixture may works… but, how is the best way to do that? Create CSV, XLS ?
Thanks
Hi there… I have more them 20k record to auto import when I install the application… using fixture may works… but, how is the best way to do that? Create CSV, XLS ?
Thanks
Hi, one way is to add a function to execute after install.
In order to do this you have to add a hook, for example:
after_install = "your_application.install.after_install"
And add a file:
your_application/setup/install.py with the function after_install, and add the .csv file in the same folder, for example:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import csv
import os.path
def after_install():
my_path = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(my_path, "your_file.csv")
with open(path, 'r') as csvfile:
reader = csv.reader(csvfile, delimiter=str(';'))
for idx, val in enumerate(reader):
if idx==0:
continue # If csv have first row with headers
# Do something with your data
doc = frappe.new_doc('DocType')
doc.property = val[0]
doc.insert()