Corrected issue with duplicate queries

This commit is contained in:
Jeremy Stretch 2016-08-17 12:41:12 -04:00
parent c49177e59c
commit 8d99ad3099
2 changed files with 6 additions and 2 deletions

View File

@ -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

View File

@ -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]