Do not update multivalue record if the value is not modified
When a ValueMixin is used for many MultiValue fields, they are created with default values when the first MultiValue is set. But often the other MultiValue fields are set with the default value so by not forcing the change, we avoid a unnecessary UPDATE query.
This commit is contained in:
1 parent
445df1ccc5
commit
5dc10a92e1
1 file changed
+8
-1
@@ -84,7 +84,14 @@ class MultiValueMixin(object):
|
||||
if not values:
|
||||
values = [self.multivalue_record(name, **pattern)]
|
||||
for record in values:
|
||||
setattr(record, name, value)
|
||||
current_value = getattr(record, name, None)
|
||||
if isinstance(current_value, Model):
|
||||
current_value = current_value.id
|
||||
elif isinstance(current_value, (list, tuple)):
|
||||
current_value = [
|
||||
r.id if isinstance(r, Model) else r for r in current_value]
|
||||
if current_value != value:
|
||||
setattr(record, name, value)
|
||||
if save:
|
||||
Value.save(values)
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user