1

I want to dynamically list all available properties from an odata Entity using PyOData package.

Here is what I'd like to do:

service = pyodata.Client(SERVICE_URL, session)

positions = service.entity_sets.TRLPositionSet.get_entities().select('Prop1,Prop2').execute()
for p in positions:
 # how to implement get_properties below?
 properties = get_properties(p)
 for prop in properties:
   print(prop.name, getattr(p, prop.name)

How would I implement the get_properties(p) function to make it return a list ['Prop1', 'Prop2']?

neves
  • 33,186
  • 27
  • 159
  • 192

1 Answers1

1

Take a look here: https://github.com/SAP/python-pyodata/issues/53#issuecomment-533261246

for es in client.schema.entity_sets: print(es.name)

proprties = es.entity_type.proprties()

for prop in es.entity_type.key_proprties:
    print(f' K {prop.name}({prop.typ.name})')
    proprties.remove(prop)

for prop in proprties:
    print(f' + {prop.name}({prop.typ.name})')

for prop in es.entity_type.nav_proprties:
    print(f' + {prop.name}({prop.to_role.entity_type_name})')

In my case I had to use es._entity_type

EinEsellesEniE
  • 129
  • 1
  • 10