Fix clearing attributes via @set.
This commit is contained in:
parent
4426f776fd
commit
4af854271a
1 changed files with 15 additions and 9 deletions
|
|
@ -595,9 +595,15 @@ class Object(models.Model):
|
||||||
if self.has_attribute(attribute):
|
if self.has_attribute(attribute):
|
||||||
# Attribute already exists, update it.
|
# Attribute already exists, update it.
|
||||||
attrib_obj = Attribute.objects.filter(attr_object=self).filter(attr_name__iexact=attribute)[0]
|
attrib_obj = Attribute.objects.filter(attr_object=self).filter(attr_name__iexact=attribute)[0]
|
||||||
|
if new_value.strip() == '':
|
||||||
|
# If you do something like @set me=SOMEATTR:, destroy the attrib.
|
||||||
|
attrib_obj.delete()
|
||||||
|
else:
|
||||||
|
# Otherwise, save over the existing attribute's value.
|
||||||
attrib_obj.attr_value = new_value
|
attrib_obj.attr_value = new_value
|
||||||
attrib_obj.save()
|
attrib_obj.save()
|
||||||
else:
|
else:
|
||||||
|
if new_value.strip() != '':
|
||||||
# Attribute object doesn't exist, create it.
|
# Attribute object doesn't exist, create it.
|
||||||
new_attrib = Attribute()
|
new_attrib = Attribute()
|
||||||
new_attrib.attr_name = attribute
|
new_attrib.attr_name = attribute
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue