def update_instance(self, instance, remove=None, objects=None): if remove is None: remove = [] if objects is None: objects = getattr(instance, self.from_field).all() items = [self._prepare(o) for o in objects if o not in remove] instance.__dict__[self.name] = dumps(items) instance.__class__.objects.filter(pk=instance.pk).update( **{self.name: instance.__dict__[self.name]})
def get_prep_value(self, value): if not isinstance(value, basestring): value = dumps(value) return super(DenormManyToManyField, self).get_prep_value(value)