Opened 2 years ago

Closed 2 years ago

#33632 closed Bug (needsinfo)

Overwriting context_object_name in list views

Reported by: Iván Legrán Owned by: nobody
Component: Generic views Version: 4.0
Severity: Normal Keywords: generic views context_object_name
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mariusz Felisiak)

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.

Change History (1)

comment:1 by Mariusz Felisiak, 2 years ago

Description: modified (diff)
Resolution: needsinfo
Status: newclosed
Summary: Overwriting 'context_object_name' in list viewsOverwriting context_object_name in list views

Hi, I don't think you've explained the issue in enough detail to confirm a bug in Django. Please reopen the ticket if you can debug your issue and provide details about why and where Django is at fault, or if you can provide a small project that reproduces this issue.

Note: See TracTickets for help on using tickets.
Back to Top