title: Customizing Django form widgets? - Django
body: <p>I'm having a little problem here!</p>
  
  <hr>
  
  <p>I have discovered the following as being the globally accepted method for customizing Django admin field.</p>
  
  <pre><code>from django import forms
  from django.utils.safestring import mark_safe
  
  class AdminImageWidget(forms.FileInput):
      """
      A ImageField Widget for admin that shows a thumbnail.
      """
  
      def __init__(self, attrs={}):
          super(AdminImageWidget, self).__init__(attrs)
  
      def render(self, name, value, attrs=None):
          output = []
          if value and hasattr(value, "url"):
              output.append(('&lt;a target="_blank" href="%s"&gt;'
                             '&lt;img src="%s" style="height: 28px;" /&gt;&lt;/a&gt; '
                             % (value.url, value.url)))
          output.append(super(AdminImageWidget, self).render(name, value, attrs))
          return mark_safe(u''.join(output))
  </code></pre>
  
  <hr>
  
  <p>I need to have access to other field of the model in order to decide how to display the field!</p>
  
  <p>For example:</p>
  
  <p>If I am keeping track of a value, let us call it "<strong>sales</strong>". </p>
  
  <p>If I wish to customize how sales is displayed depending on another field, let us call it "<strong>conversion rate</strong>".</p>
  
  <p>I have no obvious way of accessing the <strong>conversion rate</strong> field when overriding the sales widget!</p>
  
  <hr>
  
  <p>Any ideas to work around this would be highly appreciated! Thanks :)</p>