Count total and error rows

This commit is contained in:
PCoder 2021-11-25 13:48:32 +05:30
parent b0923faf88
commit ee4c340cb7

View file

@ -370,7 +370,10 @@ class Command(BaseCommand):
with open(file_path, 'r', newline='') as csv_file:
reader = csv.reader(csv_file, dialect='mydialect')
first = True
error_row_count = 0
total = 0
for row in reader:
total += 1
if first:
# Assume the first row to be the header
header = row
@ -388,8 +391,10 @@ class Command(BaseCommand):
except Range.DoesNotExist as dne:
print("this range = %s, mother range --> %s" % (row[0], row[5]))
print(str(dne))
error_row_count += 1
except ValueError as ve:
print(str(ve))
error_row_count += 1
continue
_object_dict = {self.cols_to_django_fields.get(key): value.lstrip('"').rstrip('"') for key, value in zip(header, row)}
_object_dict = handle_object_dict(_object_dict, model_name)
@ -402,6 +407,7 @@ class Command(BaseCommand):
print('----------------')
continue
print("Done importing %s" % str(_model))
print("Total rows = %s, error rows = %s" % (total, error_row_count))
def handle_object_dict(object_dict, model_name):