canadadry
canadadry

Reputation: 8443

How to assemble a link to a specific view in django admin?

Inside my subclass of admin.ModelAdmin, I want to manually assemble a url to a different edit view for a different model.

What I currently have is:

The question now is how I can obtain the prefix of the server. e.g. I access the admin via url http://myserver.com/admin/app/model/ How can I retrieve http://myserver.com/admin in a server agnostic way inside my ModelAdmin subclass ?

Upvotes: 0

Views: 121

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599490

Use the reverse function, as documented in reversing admin urls.

For example:

urlresolvers.reverse('admin:appname_modelname_change', args=(id,))

Upvotes: 3

Related Questions