[Answered ]-Django admin, change current value of ForeignKey widget

2๐Ÿ‘

โœ…

Ok, Iโ€™ve solved my problem.
My solution is to override admin/edit_inline.html template with these code:

<td class="original">
        {% if inline_admin_form.original or inline_admin_form.show_url %}
            <p>
                {% if inline_admin_form.original %}
                    <a href="{% url 'admin:MyApp_product_change' inline_admin_form.original.product.id %}">
                        {{ inline_admin_form.original }}
                    </a>
                {% endif %}
            </p>
        {% endif %}

and set the template attribute of my ModelAdmin class to corresponding url of new template.

admin.py

class MyModelInline(admin.TabularInline):
    template = "admin/myapp/mymodel/edit_inline/tabular.html"

Please comment for any better solutions! Bye ๐Ÿ˜‰

๐Ÿ‘คFabrizio A

Leave a comment