mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
7961 optimize loading csv test data
This commit is contained in:
parent
36d781a9ec
commit
4e4006dc2f
@ -333,13 +333,19 @@ class BulkImportView(GetReturnURLMixin, BaseMultiObjectView):
|
|||||||
from utilities.forms import CSVModelChoiceField
|
from utilities.forms import CSVModelChoiceField
|
||||||
new_objs = []
|
new_objs = []
|
||||||
|
|
||||||
|
ids = [int(record["id"]) for record in records]
|
||||||
|
qs = self.queryset.model.objects.filter(id__in=ids)
|
||||||
|
print(qs)
|
||||||
|
objs = {}
|
||||||
|
for obj in qs:
|
||||||
|
objs[obj.id] = obj
|
||||||
|
|
||||||
for row, data in enumerate(records, start=1):
|
for row, data in enumerate(records, start=1):
|
||||||
try:
|
if int(data["id"]) not in objs:
|
||||||
obj = self.queryset.model.objects.get(pk=data["id"])
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
form.add_error('csv', f'Row {row} id: {data["id"]} Does not exist')
|
form.add_error('csv', f'Row {row} id: {data["id"]} Does not exist')
|
||||||
raise ValidationError("")
|
raise ValidationError("")
|
||||||
|
|
||||||
|
obj = objs[int(data["id"])]
|
||||||
obj_form = self.model_form(data, headers=headers, instance=obj)
|
obj_form = self.model_form(data, headers=headers, instance=obj)
|
||||||
|
|
||||||
# The form should only contain fields that are in the CSV
|
# The form should only contain fields that are in the CSV
|
||||||
|
Loading…
Reference in New Issue
Block a user