Home:ALL Converter>django admin custom model admin url

django admin custom model admin url

Ask Time:2015-07-01T02:39:37         Author:Atul Bhatia

Json Formatter

So I have a Bookings model in my django app. I am using django admin to display information about the booking. I want to create a custom url directly from the changelist view -- (not the change view).

I want the url to be something like: /admin/bookings/generate_bookings.

I've registered that url in my model admin by overwriting the get_urls function. The issue is that django automatically resolves any url that follows the syntax of model_name/<text> as a detail view url and it assumes whatever is in text is a primary key of the given model.

As a result I get the error:

booking object with primary key u'random_text' does not exist.

Is there any way to get my custom url to resolve first?

Author:Atul Bhatia,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31145936/django-admin-custom-model-admin-url
yy