You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

28 lines
1.2 KiB

import os, sys, django, csv
from django.contrib.auth import get_user_model
sys.path.append("../")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lms.settings")
django.setup()
from finance.models import Bill, Invoice
from courses.models import Course
if __name__ == '__main__':
Bill.objects.all().delete()
with open('./finance/bill.csv') as bill_csv:
bill_reader = csv.DictReader(bill_csv)
for row in bill_reader:
bill_kwarg = dict()
row = dict(row)
bill_kwarg['id'] = row.pop('id', None)
bill_kwarg['course'] = Course.objects.get(id=row.pop('course__id', None))
opener_id = row.pop('opener__id', None)
bill_kwarg['opener'] = get_user_model().objects.get(id=opener_id) if opener_id \
else get_user_model().objects.get(email="kate.gazukina@skillbox.ru")
bill_kwarg['user'] = get_user_model().objects.get(email=row.pop('user__email', None))
bill_kwarg['comment'] = row.pop('comment', None)
bill_kwarg['description'] = row.pop('description', None)
bill = Bill.objects.create(**bill_kwarg)
Invoice.objects.create(bill=bill, **row)