<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Django simple admin ImageField thumbnail</title>
	<atom:link href="http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/</link>
	<description>folding with my brain</description>
	<lastBuildDate>Wed, 07 Dec 2011 09:53:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Francis</title>
		<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/comment-page-1/#comment-13988</link>
		<dc:creator>Francis</dc:creator>
		<pubDate>Thu, 21 Apr 2011 18:17:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.psychicorigami.com/?p=168#comment-13988</guid>
		<description>that last post got didnt keep tabs see: http://djangosnippets.org/snippets/2419/</description>
		<content:encoded><![CDATA[<p>that last post got didnt keep tabs see: <a href="http://djangosnippets.org/snippets/2419/" rel="nofollow">http://djangosnippets.org/snippets/2419/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Francis</title>
		<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/comment-page-1/#comment-13987</link>
		<dc:creator>Francis</dc:creator>
		<pubDate>Thu, 21 Apr 2011 18:09:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.psychicorigami.com/?p=168#comment-13987</guid>
		<description>Firstly thanks for this script, you got me up and going rather quickly.
I had to tweak it to create / show a thumbnail instead of the full image. this code is a combo of yours and this: http://djangosnippets.org/snippets/955/ 

from django.contrib.admin.widgets import AdminFileWidget
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
import os
import Image

class AdminImageWidget(AdminFileWidget):
	def render(self, name, value, attrs=None):
		output = []
		if value and getattr(value, &quot;url&quot;, None):
			
			image_url = value.url
			file_name=str(value)
			
			# defining the size
			size=&#039;100x100&#039;
			x, y = [int(x) for x in size.split(&#039;x&#039;)]
			
			# defining the filename and the miniature filename
			filehead, filetail 	= os.path.split(value.path)
			basename, format 	= os.path.splitext(filetail)
			miniature 			= basename + &#039;_&#039; + size + format
			filename 			= value.path
			miniature_filename 	= os.path.join(filehead, miniature)
			filehead, filetail 	= os.path.split(value.url)
			miniature_url 		= filehead + &#039;/&#039; + miniature
			
			# make sure that the thumbnail is a version of the current original sized image
			if os.path.exists(miniature_filename) and os.path.getmtime(filename) &gt; os.path.getmtime(miniature_filename):
				os.unlink(miniature_filename)
				
			# if the image wasn&#039;t already resized, resize it
			if not os.path.exists(miniature_filename):
				image = Image.open(filename)
				image.thumbnail([x, y], Image.ANTIALIAS)
				try:
					image.save(miniature_filename, image.format, quality=100, optimize=1)
				except:
					image.save(miniature_filename, image.format, quality=100)
			
			output.append(u&#039; &lt;a href=&quot;%s&quot; rel=&quot;nofollow&quot;&gt;&lt;/a&gt; %s &#039; % \
			(miniature_url, miniature_url, miniature_filename, _(&#039;Change:&#039;)))
			
		output.append(super(AdminFileWidget, self).render(name, value, attrs))
		return mark_safe(u&#039;&#039;.join(output))</description>
		<content:encoded><![CDATA[<p>Firstly thanks for this script, you got me up and going rather quickly.<br />
I had to tweak it to create / show a thumbnail instead of the full image. this code is a combo of yours and this: <a href="http://djangosnippets.org/snippets/955/" rel="nofollow">http://djangosnippets.org/snippets/955/</a> </p>
<p>from django.contrib.admin.widgets import AdminFileWidget<br />
from django.utils.translation import ugettext as _<br />
from django.utils.safestring import mark_safe<br />
import os<br />
import Image</p>
<p>class AdminImageWidget(AdminFileWidget):<br />
	def render(self, name, value, attrs=None):<br />
		output = []<br />
		if value and getattr(value, &#8220;url&#8221;, None):</p>
<p>			image_url = value.url<br />
			file_name=str(value)</p>
<p>			# defining the size<br />
			size=&#8217;100&#215;100&#8242;<br />
			x, y = [int(x) for x in size.split('x')]</p>
<p>			# defining the filename and the miniature filename<br />
			filehead, filetail 	= os.path.split(value.path)<br />
			basename, format 	= os.path.splitext(filetail)<br />
			miniature 			= basename + &#8216;_&#8217; + size + format<br />
			filename 			= value.path<br />
			miniature_filename 	= os.path.join(filehead, miniature)<br />
			filehead, filetail 	= os.path.split(value.url)<br />
			miniature_url 		= filehead + &#8216;/&#8217; + miniature</p>
<p>			# make sure that the thumbnail is a version of the current original sized image<br />
			if os.path.exists(miniature_filename) and os.path.getmtime(filename) &gt; os.path.getmtime(miniature_filename):<br />
				os.unlink(miniature_filename)</p>
<p>			# if the image wasn&#8217;t already resized, resize it<br />
			if not os.path.exists(miniature_filename):<br />
				image = Image.open(filename)<br />
				image.thumbnail([x, y], Image.ANTIALIAS)<br />
				try:<br />
					image.save(miniature_filename, image.format, quality=100, optimize=1)<br />
				except:<br />
					image.save(miniature_filename, image.format, quality=100)</p>
<p>			output.append(u&#8217; <a href="%s" rel="nofollow"></a> %s &#8216; % \<br />
			(miniature_url, miniature_url, miniature_filename, _(&#8216;Change:&#8217;)))</p>
<p>		output.append(super(AdminFileWidget, self).render(name, value, attrs))<br />
		return mark_safe(u&#8221;.join(output))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Greg</title>
		<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/comment-page-1/#comment-11385</link>
		<dc:creator>Greg</dc:creator>
		<pubDate>Tue, 16 Nov 2010 13:57:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.psychicorigami.com/?p=168#comment-11385</guid>
		<description>I have several admin.ModelAdmin sub-classes for which I want this behaviour for all ImageField fields so I use formfield_overrides.

class MyAdmin(admin.ModelAdmin):

    formfield_overrides = {
        models.ImageField: {&#039;widget&#039;: AdminImageWidget}}</description>
		<content:encoded><![CDATA[<p>I have several admin.ModelAdmin sub-classes for which I want this behaviour for all ImageField fields so I use formfield_overrides.</p>
<p>class MyAdmin(admin.ModelAdmin):</p>
<p>    formfield_overrides = {<br />
        models.ImageField: {&#8216;widget&#8217;: AdminImageWidget}}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: john</title>
		<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/comment-page-1/#comment-11017</link>
		<dc:creator>john</dc:creator>
		<pubDate>Sun, 15 Aug 2010 18:31:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.psychicorigami.com/?p=168#comment-11017</guid>
		<description>josiano,

it should just be a case of adding the formfield_for_dbfield method to your TabularInline class definition (see Daniel&#039;s comment).

John</description>
		<content:encoded><![CDATA[<p>josiano,</p>
<p>it should just be a case of adding the formfield_for_dbfield method to your TabularInline class definition (see Daniel&#8217;s comment).</p>
<p>John</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: josiano</title>
		<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/comment-page-1/#comment-11016</link>
		<dc:creator>josiano</dc:creator>
		<pubDate>Sun, 15 Aug 2010 17:59:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.psychicorigami.com/?p=168#comment-11016</guid>
		<description>hi
how could I do the same for TabularInline objects ?

cheers,
_j</description>
		<content:encoded><![CDATA[<p>hi<br />
how could I do the same for TabularInline objects ?</p>
<p>cheers,<br />
_j</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Jewett</title>
		<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/comment-page-1/#comment-10835</link>
		<dc:creator>Daniel Jewett</dc:creator>
		<pubDate>Wed, 16 Jun 2010 19:37:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.psychicorigami.com/?p=168#comment-10835</guid>
		<description>Ok, I see.  I just included the form field override in my inline class definition and it worked!
Thanks!</description>
		<content:encoded><![CDATA[<p>Ok, I see.  I just included the form field override in my inline class definition and it worked!<br />
Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Jewett</title>
		<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/comment-page-1/#comment-10834</link>
		<dc:creator>Daniel Jewett</dc:creator>
		<pubDate>Wed, 16 Jun 2010 19:00:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.psychicorigami.com/?p=168#comment-10834</guid>
		<description>Hello,
John is it?
Thanks for the widget. it works beautifully. I&#039;m wondering how I can get the widget to render in inline forms.

I have an ItemImage class with a FK relationship to Items.

It would be great if the widget would display images in the set of ItemImage change forms included on the Item change form.

Thanks,
Dan J.</description>
		<content:encoded><![CDATA[<p>Hello,<br />
John is it?<br />
Thanks for the widget. it works beautifully. I&#8217;m wondering how I can get the widget to render in inline forms.</p>
<p>I have an ItemImage class with a FK relationship to Items.</p>
<p>It would be great if the widget would display images in the set of ItemImage change forms included on the Item change form.</p>
<p>Thanks,<br />
Dan J.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phu Le</title>
		<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/comment-page-1/#comment-10808</link>
		<dc:creator>Phu Le</dc:creator>
		<pubDate>Thu, 20 May 2010 09:20:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.psychicorigami.com/?p=168#comment-10808</guid>
		<description>Thanks for this snippet!</description>
		<content:encoded><![CDATA[<p>Thanks for this snippet!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephen Wolff</title>
		<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/comment-page-1/#comment-10790</link>
		<dc:creator>Stephen Wolff</dc:creator>
		<pubDate>Sun, 25 Apr 2010 07:07:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.psychicorigami.com/?p=168#comment-10790</guid>
		<description>Hey John, nice to see you in Django land...

Here&#039;s a one liner that does the same job as your try/catch:


        request = kwargs.pop(&#039;request&#039;, None)</description>
		<content:encoded><![CDATA[<p>Hey John, nice to see you in Django land&#8230;</p>
<p>Here&#8217;s a one liner that does the same job as your try/catch:</p>
<p>        request = kwargs.pop(&#8216;request&#8217;, None)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: john</title>
		<link>http://www.psychicorigami.com/2009/06/20/django-simple-admin-imagefield-thumbnail/comment-page-1/#comment-10786</link>
		<dc:creator>john</dc:creator>
		<pubDate>Tue, 20 Apr 2010 09:52:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.psychicorigami.com/?p=168#comment-10786</guid>
		<description>The code ultimately needs to be used inside your apps admin.py file - when you register your models with the admin.

The AdminImageWidget class itself can go wherever you want it and can be imported into your admin.py file(s) as needed.</description>
		<content:encoded><![CDATA[<p>The code ultimately needs to be used inside your apps admin.py file &#8211; when you register your models with the admin.</p>
<p>The AdminImageWidget class itself can go wherever you want it and can be imported into your admin.py file(s) as needed.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

