Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions eav/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,11 @@ def save(self):
for attribute in self.get_all_attributes():
if self._hasattr(attribute.slug):
attribute_value = self._getattr(attribute.slug)
if attribute.datatype == Attribute.TYPE_ENUM and not isinstance(attribute_value, EnumValue):
if attribute.datatype == Attribute.TYPE_ENUM and not isinstance(attribute_value, EnumValue) and attribute_value:
attribute_value = EnumValue.objects.get(value=attribute_value)
if attribute.datatype == Attribute.TYPE_ENUM_MULTI:
attribute_value = [
EnumValue.objects.get(value=v) if not isinstance(attribute_value, EnumValue) else v
EnumValue.objects.get(value=v) if not isinstance(v, EnumValue) else v
for v in attribute_value
]
attribute.save_value(self.instance, attribute_value)
Expand Down
20 changes: 20 additions & 0 deletions eav/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,23 @@ def order_by(self, *fields):
order_clauses.append(term[0])

return QuerySet.order_by(query_clause, *order_clauses)

def update(self, **kwargs):
config_cls = getattr(self.model, '_eav_config_cls', None)

prefix = '%s__' % config_cls.eav_attr
new_kwargs = {}
eav_kwargs = {}

for key, value in kwargs.items():
if key.startswith(prefix):
eav_kwargs.update({key[len(prefix):]: value})
else:
new_kwargs.update({key: value})

obj = self.first()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Fix update method to work with queryset instead of a single object.

obj_eav = getattr(obj, config_cls.eav_attr)
for key, value in eav_kwargs.items():
setattr(obj_eav, key, value)
obj.save()
return super(EavQuerySet, self).update(**new_kwargs)