Can't find ObjectProperty instance when adding classes dynamically

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't find ObjectProperty instance when adding classes dynamically

Bob van 't Padje
I'm adding some classes dynamically, but for some reason I can't add an instance of my ObjectProperty to my classes. e.g. I have the following classes:
  - Drug(Thing)
  - Ingredient(Thing)
  - has_ingredients(ObjectProperty)

I would expect to be able to add an Property instance on my Drug like this:
  on onto:
     onto['Drug']['has_ingredients'] = onto['Ingredient']

But this will give an error that 'has_ingredients' in undefined. My solution for now is to create a python name like following:
   for onto:
      has_ingredients = onto['has_ingredients']
      has_ingredients.python_name = 'py_has_ingredients'
      onto['Drug'].py_has_ingredients.append(onto['Ingredient'])




Reply | Threaded
Open this post in threaded view
|

Re: Can't find ObjectProperty instance when adding classes dynamically

Bob van 't Padje
I fixed it by changing
onto['Drug'].py_has_ingredients.append(onto['Ingredient'])
to
onto['Drug'].is_a.append(onto['has_ingredients'].value(onto['Ingredient']))

Loving owlready2 btw :)