An example of how you can read from a CSV export file and save data in database / django objects
import csv
# https://docs.python.org/3/library/csv.html
from django.db import IntegrityError, DatabaseError
from django.core.management.base import BaseCommand, CommandError
from BankExport.models import BankExport
from Transaction.models import Transaction
import pprint
def handle(self, *args, **options):
csv_file = BankExport.objects.get(id='2')
with open(csv_file.export_file.path, encoding='Latin1') as csvfile: #newline='\n
transactions = csv.reader(csvfile, delimiter=';') #quotechar='|'
import pdb;pdb.set_trace()
for row in transactions:
import pdb;pdb.set_trace()
pprint.pprint(row)
Comments
Post a Comment