def get_device_by_name_or_pk(name):
 if re.match(DEVICE_BY_PK_RE, name):
  pk = name.strip('{}')
  device = Device.objects.get(pk=pk)
 else:
  device = Device.objects.get(name=name)
 return device

def get_device_by_name_or_pk ( name ) : if re . match ( DEVICE_BY_PK_RE , name ) : pk = name . strip ( '{}' ) device = Device . objects . get ( pk = pk ) else : device = Device . objects . get ( name = name ) return device
attempt to retrieve a device by either its name or primary key .