title: Book object is not iterable: Trying to display similar objects of an instance based on a field
body: <p>I am working on a library project that displays books and each both is in a category(history, math, adventure, etc). On the detailed view of a book, I want a link (with &quot;See similar books in this category&quot;) that will redirect the user to other books of the same category of the current book. So if the detail page of a book has a category of &quot;history&quot;, the link will direct to other books in the &quot;history&quot; category. The redirection is to another template (Addon: In helping me out, I would love to display the &quot;similar books&quot; in the same page, not a different page)</p>
  <p><strong>error details</strong></p>
  <pre><code>TypeError at /search/similar/bootsrtap/
  'Book' object is not iterable
  </code></pre>
  <p>models.py</p>
  <pre><code>class Category(models.Model):
  name = models.CharField(max_length=255)
  
  def __str__(self):
      return self.name
  
  def get_absolute_url(self):
      return reverse('index')
      
  choices = Category.objects.all().values_list('name', 'name')
  choice_list = []
  for item in choices:
      choice_list.append(item)
  
  class Book(models.Model):
  title = models.CharField(max_length=255)
  author = models.CharField(max_length=255)
  category = models.CharField(max_length=255, choices=choice_list)
  slug = models.SlugField(max_length=100, unique=True)
  
  def __str__(self):
      return self.author + &quot;: &quot; + self.title
  
  def get_absolute_url(self):
      return reverse('detail', kwargs={'slug': self.slug})
  
  def save(self, *args, **kwargs):
      if not self.slug:
          self.slug = slugify(self.title)
      return super().save(*args, **kwargs)
  
  def similar_book(self):
      return Book.objects.filter(category=self.category)
  </code></pre>
  <p><strong>urls.py</strong></p>
  <pre><code>urlpatterns = [
  path('detail/&lt;slug:slug&gt;/', BookDetail.as_view(), name='detail'),
  path('search/similar/&lt;slug:slug&gt;/', views.search_similar_results, name='search_similar_results'),
  </code></pre>
  <p><strong>views.py</strong></p>
  <pre><code>def search_similar_results(request, slug):
      books = get_object_or_404(Book, slug=slug)
      books.similar_book()
      return render(request, 'book/similar_results.html', {'books': books})
  
  class BookDetail(generic.DetailView):
      model = Book
      context_object_name = 'book'
      template_name = 'book/detail.html'
  
      
  
  </code></pre>
  <p><strong>clickable link to lead to the template</strong></p>
  <pre><code>&lt;a href=&quot;{% url 'search_similar_results' slug=book.slug %}&quot;&gt;Click to see Similar books in this category&lt;/a&gt;&lt;/h3&gt;
              &lt;div class=&quot;row&quot;&gt;
  </code></pre>
  <p><strong>template</strong></p>
  <pre><code>&lt;div class=&quot;row&quot;&gt;
          {% if books %}
              {% for book in books %}
  
              &lt;h2&gt;Similar Books in {{ book.category } Category}&lt;/h2&gt;
              &lt;figure class=&quot;col-lg-3 col-md-4 col-sm-6 col-12 tm-gallery-item animated bounce infinite&quot;&gt;
                  &lt;a href=&quot;{{ book.get_absolute_url }}&quot;&gt;
                  &lt;div class=&quot;tm-gallery-item-overlay&quot;&gt;
                      {% if book.cover %}
                      &lt;img src=&quot;{{ book.cover.url }}&quot; alt=&quot;Image&quot; class=&quot;img-fluid tm-img-center&quot;&gt;
                      {% endif %}
                      &lt;p class=&quot;small font-italic&quot;&gt;Author: {{ book.author }}&lt;/p&gt;
                      &lt;p class=&quot;small font-italic text-left&quot;&gt;Title: {{ book.title }}&lt;/p&gt;
                      &lt;p class=&quot;small font-italic&quot;&gt;Category: {{ book.category }}&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;/a&gt;
              &lt;/figure&gt;
              {% endfor %}
          {% else %}
          &lt;p&gt;There are No Available Books&lt;/p&gt;
          {% endif %}
  
    &lt;/div&gt;
  </code></pre>
  <p><strong>details.html</strong></p>
  <pre><code>&lt;div class=&quot;tm-main-content no-pad-b&quot;&gt;
          
      &lt;!-- Book Detail Page Display --&gt;
      &lt;section class=&quot;row tm-item-preview&quot;&gt;
          {% if book.cover %}
          &lt;div class=&quot;col-md-6 col-sm-12 mb-md-0 mb-5&quot;&gt;
              &lt;img src=&quot;{{ book.cover.url }}&quot; alt=&quot;Image&quot; class=&quot;img-fluid tm-img-center-sm card-img-top&quot;&gt;
              &lt;h2&gt;Title {{ book.title }}&lt;/h2&gt;
          &lt;/div&gt;
          {% else %}
          &lt;p&gt;No book cover&lt;/p&gt;
          {% endif %}
      &lt;/section&gt;
  
      &lt;!-- Similar Books Display by Category --&gt;
      &lt;div class=&quot;tm-gallery no-pad-b&quot;&gt;
          &lt;h3 style=&quot;color: white; text-align: center;&quot;&gt;&lt;a href=&quot;{% url 'search_similar_results' slug=book.slug %}&quot;&gt;Similar books you might be interested in&lt;/a&gt;&lt;/h3&gt;
          &lt;div class=&quot;row&quot;&gt;
              {% for item in similar_book%}
              &lt;figure class=&quot;col-lg-3 col-md-4 col-sm-6 col-12 tm-gallery-item&quot;&gt;
                  &lt;a href=&quot;{{ book.get_absolute_url }}&quot;&gt;
                      &lt;div class=&quot;tm-gallery-item-overlay&quot;&gt;
                          &lt;img src=&quot;{{ book.cover.url }}&quot; alt=&quot;Image&quot; class=&quot;img-fluid tm-img-center&quot;&gt;
                      &lt;/div&gt;
                      &lt;p class=&quot;tm-figcaption&quot;&gt;Title: {{ book.title}}&lt;/p&gt;
                      &lt;p class=&quot;tm-figcaption&quot;&gt;Category: {{ book.category }}&lt;/p&gt;
                  &lt;/a&gt;
              &lt;/figure&gt;
              {% endfor %}
          &lt;/div&gt;   
      &lt;/div&gt;                               
  &lt;/div&gt;  
  
  </code></pre>