Hi Jay,
Firstly, I would avoid calling a model “Model.” Maybe “Product” would be better? It’s only because of Django’s models.Model class. That will likely cause confusion in the future for you.
You’ll want to work with the Category model primarily and use a reverse lookup to get to the corresponding “Model” instead of working with a model_list. The reverse lookup of category to model is model_set by default. You can change the name if you want.
{% for category in category_list %}
<strong>{{ category }}</strong>
<ul>
{% for model in category.model_set %}
<li><a href="{{ model.get_absolute_url }}">{{ model }}</a></li>
{% endfor %}
</ul>
{% empty %}
<p>There is no equipment in the database with a category.</p>
{% endfor %}
Check out https://docs.djangoproject.com/en/2.1/topics/db/examples/many_to_one/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
django-users...@googlegroups.com.
To post to this group, send email to
django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/098cc4aa-374a-4e9a-9da1-ee49bab591aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To post to this group, send email to djang...@googlegroups.com.
We need to see your view code. I’m assuming now that you don’t have category_list in your context variable that you submitted to the template.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/62492e1a-1aeb-48ef-b1c1-47d3bfc77124%40googlegroups.com.
Okay, your URL should point to your CategoryListView. That should have category_list in its context. And the template should in the category_list template.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4683cba0-9332-46ac-b318-bbd25b4a32f5%40googlegroups.com.
Oh, yes. I do it all the time myself.
You need to change
category.model_set
to
category.model_set.all
model_set is the manager. You need to treat it like any other manager.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1d1057c6-3be6-4205-8530-59946090547d%40googlegroups.com.