How to do it...

Follow these steps to generate a details page for books:

  1. Add a new route for book details in main.py, as follows:
    @http.route('/books/<model("library.book"):book>', type='http', auth="user", website=True)
    def library_book_detail(self, book):
    return request.render(
    'my_library.book_detail', {
    'book': book,
    })
  2. Add a new template for book details in templates.xml, as follows:
    <template id="book_detail" name="Books Detail">
    <t t-call="website.layout">
    <div class="container">
    <div class="row mt16">
    <div class="col-5">
    <span t-field="book.image" t-options="{
    'widget': 'image',
    'class': 'mx-auto d-block img-thumbnail'}"/>
    </div>
    <div class="offset-1 col-6">
    <h1 t-field="book.name"/>
    <t t-if="book.date_release">
    <div t-field="book.date_release"
    class="text-muted"/>
    </t>
    <b class="mt8"> Authors </b>
    <ul>
    <li t-foreach="book.author_ids" t-as="author">
    <span t-esc="author.name" />
    </li>
    </ul>
    </div>
    </div>
    </div>
    <div t-field="book.html_description"/>
    </t>
    </template>
  3. Add a button in the book list template, as follows. This button will redirect to the book details web page:
    ...
    <div t-attf-class="card mt24 #{'bg-light' if book_odd else ''}">
    <div class="card-body">
    <h3 t-field="book.name"/>
    <t t-if="book.date_release">
    <div t-field="book.date_release" class="text-muted"/>
    </t>
    <b class="mt8"> Authors </b>
    <ul>
    <li t-foreach="book.author_ids" t-as="author">
    <span t-esc="author.name" />
    </li>
    </ul>
    <a t-attf-href="/books/#{book.id}" class="btn btn-primary btn-sm">
    <i class="fa fa-book"/> Book Detail
    </a>
    </div>
    </div>
    ...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset