Count total and error rows
This commit is contained in:
parent
b0923faf88
commit
ee4c340cb7
1 changed files with 6 additions and 0 deletions
|
@ -370,7 +370,10 @@ class Command(BaseCommand):
|
||||||
with open(file_path, 'r', newline='') as csv_file:
|
with open(file_path, 'r', newline='') as csv_file:
|
||||||
reader = csv.reader(csv_file, dialect='mydialect')
|
reader = csv.reader(csv_file, dialect='mydialect')
|
||||||
first = True
|
first = True
|
||||||
|
error_row_count = 0
|
||||||
|
total = 0
|
||||||
for row in reader:
|
for row in reader:
|
||||||
|
total += 1
|
||||||
if first:
|
if first:
|
||||||
# Assume the first row to be the header
|
# Assume the first row to be the header
|
||||||
header = row
|
header = row
|
||||||
|
@ -388,8 +391,10 @@ class Command(BaseCommand):
|
||||||
except Range.DoesNotExist as dne:
|
except Range.DoesNotExist as dne:
|
||||||
print("this range = %s, mother range --> %s" % (row[0], row[5]))
|
print("this range = %s, mother range --> %s" % (row[0], row[5]))
|
||||||
print(str(dne))
|
print(str(dne))
|
||||||
|
error_row_count += 1
|
||||||
except ValueError as ve:
|
except ValueError as ve:
|
||||||
print(str(ve))
|
print(str(ve))
|
||||||
|
error_row_count += 1
|
||||||
continue
|
continue
|
||||||
_object_dict = {self.cols_to_django_fields.get(key): value.lstrip('"').rstrip('"') for key, value in zip(header, row)}
|
_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)
|
_object_dict = handle_object_dict(_object_dict, model_name)
|
||||||
|
@ -402,6 +407,7 @@ class Command(BaseCommand):
|
||||||
print('----------------')
|
print('----------------')
|
||||||
continue
|
continue
|
||||||
print("Done importing %s" % str(_model))
|
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):
|
def handle_object_dict(object_dict, model_name):
|
||||||
|
|
Loading…
Reference in a new issue