python - How can I get the object count for a model in Django's templates? -
I am applying my own demo, I am bringing all things for a particular model like:
< Pre> secs = sections.objects.filter (order__gt = 5) I can use all properties of models such as this varbiles near my templates and i section . Name is a model named , section.id , etc
books in which sections models when I I repeat the template in seconds varible, so how can I get count of books for each section? {{sec.books.count}} ?? Something like "Text">
Books in
thanks
Sections , then DJO will automatically create reverse relationships from books with sections, which is
books_set . This is a manager, which means that you can use .filter () , .get () and .count () - And you can use it in your template. {{sec.books_set.count}} (By the way, you should use singular nouns for your model name, not plural - < Books instead of code> book . An example of that model keeps information for a book, not many.)
Comments
Post a Comment