

def __set__(self, instance, value):
    if isinstance(value, self.rel_model):
        instance._data[self.att_name] = getattr(value, self.field.to_field.name)
        instance._obj_cache[self.att_name] = value
    else:
        orig_value = instance._data.get(self.att_name)
        instance._data[self.att_name] = value
        if ((orig_value != value) and (self.att_name in instance._obj_cache)):
            del instance._obj_cache[self.att_name]
    instance._dirty.add(self.att_name)

dataset/ETHPy150Open coleifer/peewee/peewee.py RelationDescriptor.__set__/original