One small correction, in 'list_display' it should be 'admin_photo' (or I'd 
probably put 'display_photo' (see #1 below)), not 'photo'.
Some other tricks:

1) If you don't want to clog up your Model class, you can put the function 
in your ModelAdmin class.
2) If you add "readonly_fields = ('display_photo', )" you can also add 
'display_photo' to 'fields' or 'fieldsets' to show it on the individual 
page (though you should make sure it works when the object hasn't been 
saved yet.)

class MyModelAdmin(admin.ModelAdmin):
    list_display = (..., 'display_photo',)
    fields = (..., 'photo', 'display_photo',)
    readonly_fields = (..., 'display_photo',)

    def display_photo(self, obj):
        if obj.id:
            return '<img src="%s" height="150">' % obj.photo.url
        return ''
    display_photo.allow_tags = Trueadmin.site.register(MyModel, MyModelAdmin)


On Monday, April 15, 2013 3:28:28 AM UTC-7, slim wrote:
>
>
> in your model create a function
>
> *def admin_photo(self):*
> *        return '<img src="%s" height="150"/>' % self.photo.url*
> *    admin_photo.allow_tags = True*
>
> then just add it in the display list :
>
> *class MymodelAdmin(admin.ModelAdmin):*
> *    list_display = (...,'photo')  *
> *admin.site.register(Mymodel, MymodelAdmin)*
>
>
>
> Le mardi 9 avril 2013 11:33:43 UTC, frocco a écrit :
>>
>> Hello,
>>
>> I have a standard image field in my model, and want to see the images on 
>> the admin list page.
>>
>> how do I modify admin.py to do this?
>>
>> Thanks
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to