Handle single model import similarly to all

This commit is contained in:
PCoder 2021-11-22 19:41:34 +05:30
parent e9d545fdd1
commit a35e6153a8

View file

@ -343,7 +343,17 @@ class Command(BaseCommand):
else:
_model = apps.get_model(options.get('app_name', 'app'), options['model_name'])
model_name = options['model_name']
file_path = options.get('path')
k = ''
csv_file_name = ''
for k, v in self.csv_files_models_dict.items():
if v.strip().lower() == model_name.strip().lower():
csv_file_name = k
if k == '':
raise Exception('Could not find a csv file name for model %s' % model_name)
if csv_folder_path.endswith('/'):
file_path = '%s%s' % (csv_folder_path, csv_file_name)
else:
file_path = '%s/%s' % (csv_folder_path, csv_file_name)
csv.register_dialect(
'mydialect',
delimiter=',',