[Django]-Filtering Django form fields by traversing more than one relationship (foreign key to foreign key?)

2👍

You can traverse more relationships by listing them all connected by double underscore,
e.g. 'region' + '__' + 'country'. Country is not directly accessible from district, but only via region in your model.

self.fields['district'].limit_choices_to = {'region__country': self.data['country']}

Leave a comment