Changes between Initial Version and Version 1 of Ticket #13848


Ignore:
Timestamp:
Jun 28, 2010, 2:44:02 PM (14 years ago)
Author:
Alex Gaynor
Comment:

Reformated code, please use preview in the future.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #13848 – Description

    initial v1  
    44
    55Below is the code to duplicate it:
    6 
     6{{{
    77class Foo(models.Model):
    88    title = models.CharField(max_length=50)
     
    1010class Photo(models.Model):
    1111    image = models.ImageField(upload_to='')
    12 
     12}}}
    1313In a view I pass all Foos objects to the template. And attempt to retrieve just the first image to be displayed but first it is passed to a filter to create a thubmnail.
    1414
    1515Here is the rough template code that generates the error: Caught AttributeError while rendering: 'str' object has no attribute 'path'.
    16 
     16{{{
    1717{% for foo in foos %}
    1818   <img alt='image' src='{{ foo.photo_set.all.0.image|thumbnail:'200x200 }}
    1919{% endfor %}
    20 
     20}}}
    2121The thumbnail filter is called twice - print typeof(file) statement in the filter outputs:
     22{{{
    2223<class 'django.db.models.fields.files.ImageFieldFile'>
    2324<type 'str'>
    24 
     25}}}
    2526A workarround is insert another loop like this:
    26 
     27{{{
    2728{% for foo in foos %}
    2829   {% for photo in foo.photo_set.all %}
     
    3233   {% endfor %}
    3334{% endfor %}
    34 
     35}}}
    3536Thank you for looking into it.
    3637
    3738---- thumbnail filter code ----
     39{{{
    3840# Author Daniel Sokolowski (danols@danols.com)
    3941#
     
    101103
    102104register.filter(thumbnail)
    103 
    104 
    105 
    106 
    107 
     105}}}
Back to Top