+ if self.field in instance._added_attribute_registry:
+ del instance._added_attribute_registry[self.field]
+ instance._removed_attribute_registry.append(self.field)
+
+
+class JSONAttributeDescriptor(AttributeFieldDescriptor):
+ def __set__(self, instance, value):
+ if self.field in instance._removed_attribute_registry:
+ instance._removed_attribute_registry.remove(self.field)
+ instance._added_attribute_registry[self.field] = value
+
+
+class ForeignKeyAttributeDescriptor(AttributeFieldDescriptor):
+ def __set__(self, instance, value):
+ if isinstance(value, (models.Model, type(None))):
+ if self.field in instance._removed_attribute_registry:
+ instance._removed_attribute_registry.remove(self.field)
+ instance._added_attribute_registry[self.field] = value
+ else:
+ raise AttributeError('The \'%s\' attribute can only be set using existing Model objects.' % self.field.name)
+
+
+class ManyToManyAttributeDescriptor(AttributeFieldDescriptor):
+ def __set__(self, instance, value):
+ if isinstance(value, models.query.QuerySet):
+ if self.field in instance._removed_attribute_registry:
+ instance._removed_attribute_registry.remove(self.field)
+ instance._added_attribute_registry[self.field] = value
+ else:
+ raise AttributeError('The \'%s\' attribute can only be set to a QuerySet.' % self.field.name)