26👍
✅
You can use a double underscore in the keyword passed to filter()
to access fields in a foreign key relationship. Like this:
Item.objects.filter(parent__name="xyz")
2👍
- Using django models across apps?
- Why is Django's Meta an old-style class?
- Yuglify compressor can't find binary from package installed through npm
- Django admin.TabularInline auto insert three blank row
- Django pass variable into template
1👍
Just for future reference for Googlers, with recent versions of Django you have to use an additional method in the keyword. For example, instead of parent__name
you have to do parent__name__exact
. Cato’s link contains other examples.
Source:stackexchange.com