1

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?

1 Answer 1

1

if you do:

def get_urls(self):
    urls = super(BookingAdmin, self).get_urls()
    my_urls = patterns('',
        (r'^generate_bookings/$', self.your_custom_function)
    )
    return my_urls + urls

and in changelist template somewhere:

<a href="generate_bookings/">Generate Booking</a>

it should work. It always worked for me at least

Sign up to request clarification or add additional context in comments.

1 Comment

It works fine on the change view. Not on the changelist view

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.