Template source: publications/admin/_img_preview_js.html

<script> $(function () { var field_id = 'id_featured_image'; var field = $('#' + field_id); field.change(function () { var new_value = $(this).val(); var pk; if (new_value !== null) { pk = new_value[0]; } else { pk = null; } set_img(pk); }); field.change(); function set_img(pk) { var img_preview_id = field_id + '_preview'; var img_preview = $('#' + img_preview_id); if (!img_preview.length) { var controls_container = $(field.parents('.controls')[0]); controls_container.append('<div id="' + img_preview_id + '"></div>'); img_preview = $('#' + img_preview_id); } if (pk == null) { img_preview.html(''); } else { var get_img_url = "{% url 'admin:ajax_get_img_url' %}?pk=" + pk; $.get(get_img_url, function (response) { img_preview.html('<img src="' + response.url + '" />'); }); } } }); </script>