[Fixed]-Getting items in model referenced by a onetoonemodel in django

1👍

clinic.menu.objects is the ModelManager for the Menu model – note that it’s an attribute of the Menu class, not of your clinic.menu instance. ModelManager classes are used to query the underlying table, and are not supposed to be called directly from instances (which wouldn’t make much sense anyway), hence the error message.

Conceptually it seems like I should be able to access the items and get a list by tracing the relationship down through the clinic model like this Clinic > Menu > Items

That’s indeed possible (hopefully), but where are you mentionning items in clinic.menu.objects ? You want clinic.menu.item_set.all().

0👍

Try this:

Clinic.objects.get(pk=1).menu.item_set.all()

Leave a comment