def dbref_to_obj(inp, objclass, raise_errors=True):
 dbid = dbref(inp)
 if (not dbid):
  return inp
 try:
  if (dbid < 0):
   return None
 except ValueError:
  return None
 try:
  return objclass.objects.get(id=dbid)
 except Exception:
  if raise_errors:
   raise
  return inp

def dbref_to_obj ( inp , objclass , raise_errors = True ) : dbid = dbref ( inp ) if ( not dbid ) : return inp try : if ( dbid < 0 ) : return None except ValueError : return None try : return objclass . objects . get ( id = dbid ) except Exception : if raise_errors : raise return inp
convert a #dbref to a valid object .