title: Link To Foreignkey in Admin Causes AttributeError When Debug Is False
body: <p>I have used the following code in my models.py file:</p>
  
  <p>Create hyperlink to foreignkey  </p>
  
  <pre><code>class ModelAdminWithForeignKeyLinksMetaclass(MediaDefiningClass): 
  
      def __getattr__(cls, name):
  
          def foreign_key_link(instance, field):
              target = getattr(instance, field)
              return u'&lt;a href="../../%s/%s/%s"&gt;%s&lt;/a&gt;' % (
                  target._meta.app_label, target._meta.module_name, target.id, unicode(target))
  
          if name[:8] == 'link_to_':
              method = partial(foreign_key_link, field=name[8:])
              method.__name__ = name[8:]
              method.allow_tags = True
              setattr(cls, name, method)
              return getattr(cls, name)
          raise AttributeError
  </code></pre>
  
  <p>In admin.py list_display I've added link_to to the beginning of each field I want a foreignkey link on. This works really well however when I turn debug off I get an attribute error. Any suggestions?</p>