I want to make a table in the html page so that every time the admins input a new object sub_category (a predetermined class) it will update the table.
For reference im trying to make something like this:
Here is my code, thank you in advanced!
HTML page that displays the table:
{% extends 'item_type/base.html' %}
{% block content %}
<h1>Clothing</h1>
<table>
{% for j in sub_category %}
{% with x=0 %}
<tr>
{% while x<4 %}
<td> <a href="{% url 'show_subcategory' j.id %}"> {{j}}</td>
{% endwhile %}
</tr>
<tr>
{% while x>4 and x<8%}
<td> <a href="{% url 'show_subcategory' j.id %}"> {{j}}</td>
{% x+=1%}
{% endwhile %}
</tr>
{% x+=1%}
{% endwith %}
{% endfor %}
</table>
{% endblock %}
Class where sub categories are created (ignore the spelling of category!)
class SubCategorie(models.Model):
sub_category = models.CharField('Clothing Type',max_length=100)
def __str__(self):
return self.sub_category
Function in views.py thats linked to the html page
def clothing(request):
sub_category = SubCategorie.objects.all()
rows = [1,2,3]
columns = [1,2,3,4]
context = {'sub_category':sub_category,'rows':rows,'columns':columns}
return render(request,'item_type/clothing.html',context )