filter database

Hey guys Im new in Python django

how can I use filter with 2 table

I have table:
book(name, description, author_id)
author(firstName, lastName)

in my views, I need to filter for I can get author-name

def get_queryset(self):
author = Author.object.filter(id = author_id)

how can I create the relationship and get the author’s name?

A good place to start is with the appropriate documentation, in this case, the query documentation on Retrieving objects, the Lookup API Reference, and the Related Objects Reference.

If you’re not comfortable with these topics, then I’d recommend going back to basics and working your way through either or both of the official Django Tutorial, and the Django Girls Tutorial.

Ken

1 Like