Browse Source

Corrected issue with duplicate queries

Jeremy Stretch 8 years ago
parent
commit
8d99ad3099
2 changed files with 6 additions and 2 deletions
  1. 4 1
      netbox/extras/forms.py
  2. 2 1
      netbox/utilities/views.py

+ 4 - 1
netbox/extras/forms.py

@@ -111,7 +111,10 @@ class CustomFieldBulkEditForm(forms.Form):
         super(CustomFieldBulkEditForm, self).__init__(*args, **kwargs)
 
         # Add all applicable CustomFields to the form
+        custom_fields = []
         for name, field in get_custom_fields_for_model(self.obj_type, bulk_editing=True).items():
             field.required = False
             self.fields[name] = field
-            self.custom_fields.append(name)
+            custom_fields.append(name)
+
+        self.custom_fields = custom_fields

+ 2 - 1
netbox/utilities/views.py

@@ -339,7 +339,8 @@ class BulkEditView(View):
             if form.cleaned_data[name] not in [None, u'']:
                 for pk in pk_list:
                     try:
-                        cfv = CustomFieldValue.objects.get(field=form.fields[name].model, obj_type=obj_type, obj_id=pk)
+                        cfv = CustomFieldValue.objects.select_related('field').get(field=form.fields[name].model,
+                                                                                   obj_type=obj_type, obj_id=pk)
                     except CustomFieldValue.DoesNotExist:
                         cfv = CustomFieldValue(field=form.fields[name].model, obj_type=obj_type, obj_id=pk)
                     cfv.value = form.cleaned_data[name]