I am new to Django and trying to pass an author\'s name to a view and filter out quote objects based on the author\'s name. here are the codes:
models.py
<
I have faced and solved similar issue,
focus on attribute : author = models.ForeignKey(Author)
django expect that you pass an Instance of Author
class to the author
field. When you search django want to get a id (a integer number of this Instance):
so to get :
aquotelist = Quote.objects.filter(author__exact = name)
you have to start by :
create obj_Author = Author.objects.get(author_name = name)
aquotelist = Quote.objects.get(author__exact = obj_Author.id)
PS: ( I used get()
in my example but if you expect to get multiple record, you can you use filter()
and modify something. but main point is that because you work with a "ForeignKey
field" so you need to give it a id
like obj_Author.id
. )