title: Django display table in templates
body: <p>I am using Django 2.0.1, and I have the following code:</p>
  
  <pre><code>Models.py:
  class Category(models.Model):
      category_name = models.CharField(max_length=50)
  
  class CategoryItems(models.Model):
      category_name = = models.ForeignKey(Categories, related_name='categoriesfk', on_delete=models.PROTECT)
      item_name = models.CharField(max_length=50)
      item_description = models.CharField(max_length=100)
  </code></pre>
  
  <p>Thereafter my views.py:</p>
  
  <pre><code>def data(request):
      categories_query = Categories.objects.all()
      category_items_query = CategoriesItems.objects.all()
  
  return render_to_response("data.html", 
  {'categories_query': categories_query,'category_items_query': category_items_query}
  </code></pre>
  
  <p>In the template I'm trying to display all items for each category, for example, suppose there are 4 categorizes, e.g. Bicycle, then it display all items belonging to that category only. For example, as follows:</p>
  
  <p><strong>Category 1:</strong><br>
  Category_Item 1,<br>
  Category_Item 2,<br>
  Category_Item 3, <br>
  and so on ...<br></p>
  
  <p><strong>Category 2:</strong><br>
  Category_Item 1,<br>
  Category_Item 2,<br>
  Category_Item 3, <br>
  and so on ...<br></p>
  
  <p>I have tried to write so many different for-loops, but they just display all items, I need it to show items only for that category, then for loop to next category and show items for that.</p>