Changes between Initial Version and Version 1 of Ticket #13848
- Timestamp:
- Jun 28, 2010, 2:44:02 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #13848 – Description
initial v1 4 4 5 5 Below is the code to duplicate it: 6 6 {{{ 7 7 class Foo(models.Model): 8 8 title = models.CharField(max_length=50) … … 10 10 class Photo(models.Model): 11 11 image = models.ImageField(upload_to='') 12 12 }}} 13 13 In 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. 14 14 15 15 Here is the rough template code that generates the error: Caught AttributeError while rendering: 'str' object has no attribute 'path'. 16 16 {{{ 17 17 {% for foo in foos %} 18 18 <img alt='image' src='{{ foo.photo_set.all.0.image|thumbnail:'200x200 }} 19 19 {% endfor %} 20 20 }}} 21 21 The thumbnail filter is called twice - print typeof(file) statement in the filter outputs: 22 {{{ 22 23 <class 'django.db.models.fields.files.ImageFieldFile'> 23 24 <type 'str'> 24 25 }}} 25 26 A workarround is insert another loop like this: 26 27 {{{ 27 28 {% for foo in foos %} 28 29 {% for photo in foo.photo_set.all %} … … 32 33 {% endfor %} 33 34 {% endfor %} 34 35 }}} 35 36 Thank you for looking into it. 36 37 37 38 ---- thumbnail filter code ---- 39 {{{ 38 40 # Author Daniel Sokolowski (danols@danols.com) 39 41 # … … 101 103 102 104 register.filter(thumbnail) 103 104 105 106 107 105 }}}