[Answered ]-Querying through four models in Django

1👍

Just use the double-underscore notation to make lookups that span relationships. In this case, it could be done like this:

transfer_lines = TransferLine.objects.filter(transfer__mobility=mobility, 
                                             organism=organism)

1👍

Another approach would be to use the ForeignKey reverse relation:

tlines = my_organisam.transferline_set.filter(transfer__mobility=my_mobility)
👤Todor

Leave a comment