Skip to content

Commit

Permalink
Added flag to clean table before import.
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard committed Dec 31, 2019
1 parent 2f8ac89 commit 05a9578
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def __init__(self, class_instance, sheet_numbered_from_1=1):
self.sheet_numbered_from_1 = sheet_numbered_from_1
self.inserter = BulkInserter(self.class_instance)
self.mandatory_column_headers = None
self.is_clean_before_import = False

def set_clean_before_import(self):
self.is_clean_before_import = True

def import_excel(self, full_path, header_row_numbered_from_1=1, first_import_row_numbered_from_1=2, count=1000):
filename = os.path.basename(full_path)
Expand All @@ -51,6 +55,9 @@ def import_excel(self, full_path, header_row_numbered_from_1=1, first_import_row

self.validate_existence_of_mandatory_columns(data_source)

if self.is_clean_before_import:
self.class_instance.objects.all().delete()

column_to_db_field_mapping = self._get_column_to_db_field_mapping(data_source)

for item_info_dict in data_source.enumerate_mapped(column_to_db_field_mapping,
Expand Down

0 comments on commit 05a9578

Please sign in to comment.