Categories
Python Answers

How to filter on foreign key properties with Python Django?

Spread the love

Sometimes, we want to filter on foreign key properties with Python Django.

In this article, we’ll look at how to filter on foreign key properties with Python Django.

How to filter on foreign key properties with Python Django?

To filter on foreign key properties with Python Django, we call filter with an argument with the name that includes the foreign key field name,

For instance, we write

Asset.objects.filter( project__name__contains="Foo" )

to call filter with the project table’s name field property including the string 'Foo'.

Conclusion

To filter on foreign key properties with Python Django, we call filter with an argument with the name that includes the foreign key field name,

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *