Django iterate through model objects that contain another particular model object in a ManyToManyField
I have the following models in my django app.
A author definately have written multiple books. A single book can also have multiple authors.
I want to iterate through all books by a particular author. Till now I have tried
for b in book.objects.filter(authors__name='HiDe'):
AttributeError: 'function' object has no attribute 'objects' probably because authors in book is a ManyToManyField.
books=models.ManyToManyField(author) will make the database large and cumbersome to manage as an author can have too many books, so this is not the solution I want.
How do you define the
It seems it is just a function. Not a model object.
The error tells you
books doesn't have the attribute
objects, and is a function.
It is also generally good practice to capitalise the first letter of Django models.