[Django] #33632: Overwriting 'context_object_name' in list views

30 views
Skip to first unread message

Django

unread,
Apr 10, 2022, 4:12:07 AM4/10/22
to django-...@googlegroups.com
#33632: Overwriting 'context_object_name' in list views
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
ivanlegranbizarro |
Type: Bug | Status: new
Component: Generic | Version: 4.0
views | Keywords: generic views
Severity: Normal | context_object_name
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I have found that when I override the context object name in a ListView it
is impossible for me to iterate correctly in a for loop in the template.
For example, if I am writing a list view called 'Services' and override
the context object name as 'services', using the for loop as follows:
{% for service in services %}
<p>
{{ service.name }}
</p>
<p>
{{ service.description }}
</p>
{% endfor %}

I find that instead of iterating over the number of items that I have
stored in the database, it does so over a crazy number of items that I
don't know what they are related to.

The same code works perfectly on Django 3.xx, and I can iterate normally
in the loop if I use the 'object_list' which its provided by default.

--
Ticket URL: <https://code.djangoproject.com/ticket/33632>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages