mirror of
https://github.com/jazzband/django-eav2.git
synced 2026-04-03 23:20:35 +00:00
Add custom update method
This commit is contained in:
parent
c03101620a
commit
cbc59280b8
2 changed files with 21 additions and 1 deletions
|
|
@ -572,7 +572,7 @@ class Entity(object):
|
|||
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 = [
|
||||
|
|
|
|||
|
|
@ -376,3 +376,23 @@ class EavQuerySet(QuerySet):
|
|||
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()
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue