'Set player or obj to their right database field. If
a dbref is given, assume ObjectDB.'

def __set_obj(self, value):

    try:
        value = _GA(value, 'dbobj')
    except AttributeError:
        pass
    if isinstance(value, (basestring, int)):
        from evennia.objects.models import ObjectDB
        value = to_str(value, force_string=True)
        if (value.isdigit() or value.startswith('#')):
            dbid = dbref(value, reqhash=False)
            if dbid:
                try:
                    value = ObjectDB.objects.get(id=dbid)
                except ObjectDoesNotExist:
                    pass
    if (value.__class__.__name__ == 'PlayerDB'):
        fname = 'db_player'
        _SA(self, fname, value)
    else:
        fname = 'db_obj'
        _SA(self, fname, value)
    _GA(self, 'save')(update_fields=[fname])
