Two foreign keys in one model

  Kiến thức lập trình

I am making my first Django app and I am having trouble exporting some values.

I have a model let’s call it Machines with some attributes (buyer, name, model, serial number etc).

My other model is a visit category model that has 2 reasons for the visit (service, inspection)

Finally I have my last model that has visitDetails (date of visit, notes, reason of visit (which is visit category model foreign key, and machine details (which is Machines model foreign key).

How can I get for each visitDetails the reason of visit?

I managed to get all machineDetails for each Machine with:

machine = Machines.objects.get(id=id)
visit_details = machine.details.all() – details is relate_name for machine_details which is an object inside visitDetails model with foreign key Machines.

But I cannot figure out how to also get visit category for each visit.

New contributor

Doc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

LEAVE A COMMENT