Make hyperlinks for labels of raw_id_fields (jQuery)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
{% block extrahead %}
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
//<![CDATA[
    jQuery(function($) {
        // Make hyperlinks for labels of raw_id_fields
        $('a.related-lookup').each(function() {
            var td = $(this).parent();
            var id = $('input', td).val();
            var url = $(this).attr('href').split('?')[0] + id + '/';
            $('strong', td).wrap('<a href="' + url + '"></a>');
        });
    });
//]]>
</script>
{% endblock %}

More like this

  1. Link raw_id_fields (both ForeignKeys and ManyToManyFields) to their change pages by EmilStenstrom 1 year, 4 months ago
  2. Confirm alert if the user navigates away without saving changes by mrazzari 2 years, 6 months ago
  3. Admin Hack: Quick lookup of GenericForeignKey id by ContentType by adnan 3 years, 4 months ago
  4. Admin Input Field Character Count via jQuery by joshman 3 years, 2 months ago
  5. jQuery slugify plugin by girasquid 2 years, 9 months ago

Comments

mbrochh (on October 25, 2011):

I think it is even better to put this into admin/change_form.html instead of admin/base_site.html

Also, you can combine this with this http://djangosnippets.org/snippets/1376/ snippet and add {% extends "admin:admin/change_form.html" %} on top of your change_form.html. That way you don't need to copy the whole file from the admin app.

#

(Forgotten your password?)