Issue With Using Query In Django
So what I'm trying to get is the following. User can choose 3 categories as seen in the code. Inside those categories they can add any number of plants. In my view: collection I wa
Solution 1:
Imho this causes the problem: You don't refer to the object/queryset correctly, so no data is being rendered frontend wise.
Your context contains the object plant_categories
which should be looped accordingly:
<ul>
{% for category in plant_categories %}
<h3>{{ category }}</h3>
# Refer to object within context
{% for name in plant_categories %}
<li>{{ name.plant }}</li> # Depending on what you would like to render you have to adapt here
{% endfor %}
{% empty %}
<li>No category has been added yet.</li>
{% endfor %}
You can add a print statement to your view to check the queryset:
def collection(request):
"""The page that opens the collection of plants"""
plant_categories = Plant_category.objects.all().order_by('category')
context = {
'plant_categories': plant_categories,
}
# Print for debugging
print(plant_categories)
return render(request, 'plntz_main/collection.html', context)
Post a Comment for "Issue With Using Query In Django"