Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32085 closed New feature (invalid)

Add template tag for creating link to admin site

Reported by: Dart Owned by: nobody
Component: Template system Version: 3.1
Severity: Normal Keywords: Tags, Admin, Urls
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hey! In some situations during development django apps, i need some way to create link into django admin for changing, deleting specific model instance.
Looking into of souces django you can see, that django has prefix names for dynamic models. For more look at get_urls() method from ModelAdmin.
Example:
info = self.model._meta.app_label, self.model._meta.model_name
url = path('add/', wrap(self.add_view), name='%s_%s_add' % info)
I am propose to write template tag which accept any model instance and action (update, delete, etc) and return correct url for django admin site.
Maybe this situation is too rare, its need some discussion.
Regards, Viktor Lomakin

Change History (2)

comment:1 by Carlton Gibson, 4 years ago

Resolution: invalid
Status: newclosed

Hi Viktor.

Please see the Reversing admin URLs docs for how you'd do this already, using the {% url %} and the provided admin_urlname filter.

From the docs there:

{% load admin_urls %}
<a href="{% url opts|admin_urlname:'add' %}">Add user</a>
<a href="{% url opts|admin_urlname:'delete' user.pk %}">Delete this user</a>

comment:2 by Dart, 4 years ago

Thanks!

Note: See TracTickets for help on using tickets.
Back to Top