- def get_value_class(self, value):
- if isinstance(value, models.query.QuerySet):
- return ManyToManyValue
- elif isinstance(value, models.Model) or (value is None and self.value_content_type.model_class() is ForeignKeyValue):
- return ForeignKeyValue
- else:
- return JSONValue
-
- def set_value(self, value):
- # is this useful? The best way of doing it?
- value_class = self.get_value_class(value)
-
- if self.value is None or value_class != self.value_content_type.model_class():
- if self.value is not None:
- self.value.delete()
- new_value = value_class()
- new_value.value = value
- new_value.save()
- self.value = new_value
- else:
- self.value.value = value
- self.value.save()
-