#33632: Overwriting context_object_name in list views
-------------------------------------+-------------------------------------
     Reporter:  Iván Legrán          |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Generic views        |                  Version:  4.0
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:  generic views        |             Triage Stage:
  context_object_name                |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * status:  new => closed
 * resolution:   => needsinfo


Old description:

> 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.

New description:

 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.

--

Comment:

 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.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018016d65c60-a4b798eb-d7e1-48a9-8b85-94f8e67f4a92-000000%40eu-central-1.amazonses.com.

Reply via email to