

def __set__(self, instance, value):
    if (instance is None):
        raise AttributeError(('%s must be accessed via instance' % self.field.name))
    if ((value is None) and (self.field.null == False)):
        raise ValueError(('Cannot assign None: "%s.%s" does not allow null values.' % (instance._meta.object_name, self.field.name)))
    elif ((value is not None) and (not isinstance(value, self.field.rel.to))):
        raise ValueError(('Cannot assign "%r": "%s.%s" must be a "%s" instance.' % (value, instance._meta.object_name, self.field.name, self.field.rel.to._meta.object_name)))
    elif (value is not None):
        if (instance._state.db is None):
            instance._state.db = router.db_for_write(instance.__class__, instance=value)
        elif (value._state.db is None):
            value._state.db = router.db_for_write(value.__class__, instance=instance)
        elif ((value._state.db is not None) and (instance._state.db is not None)):
            if (not router.allow_relation(value, instance)):
                raise ValueError(('Cannot assign "%r": instance is on database "%s", value is on database "%s"' % (value, instance._state.db, value._state.db)))
    if (value is None):
        related = getattr(instance, self.cache_name, None)
        if (related is not None):
            setattr(related, self.field.related.get_cache_name(), None)
    try:
        val = getattr(value, self.field.rel.get_related_field().attname)
    except AttributeError:
        val = None
    setattr(instance, self.field.attname, val)
    setattr(instance, self.cache_name, value)
    if ((value is not None) and (not self.field.rel.multiple)):
        setattr(value, self.field.related.get_cache_name(), val)

dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/django/db/models/fields/related.py ReverseSingleRelatedObjectDescriptor.__set__/VarMisuse@438/582 `instance`->`val`