import csv from datetime import datetime from .models import Ticker with open(FILENAME, 'r' ) as theFile: reader = csv.DictReader(theFile) for line in reader: dt = datetime.strptime(line['Date/Time'], '%m/%d/%Y %H:%M %p') expiration_date = datetime.strptime(line['Expiration Date'], '%m/%d/%Y') ticker, created = Ticker.objects.get_or_create( symbol=line['Symbol'] ) print(ticker) t, created = OptionsTrade.objects.get_or_create( date=dt, transaction_code=line['Transaction Code'], transaction_subcode=line['Transaction Subcode'], symbol=ticker, buy_sell=line['Buy/Sell'], open_close=line['Open/Close'], quantity=int(line['Quantity']), expiration_date = expiration_date, strike = line['Strike'], call_put = line['Call/Put'], price = line['Price'], fees = line['Fees'], amount = line['Amount'], description = line['Description'] ) if created: print(t)