Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 3 months ago by StarPioneer357

How can I generate a Django Admin URL with preselected objects and a default action?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

I want to create a link that directs users to a Django Admin page for a specific model, with certain objects already selected and a dropdown action pre-filled.

I've tried the following code:

PYTHON
def get_admin_action_link(record, action): app_label = record._meta.app_label model = record._meta.model_name id = record.id env = f"{settings.env}.myurl.com" if settings.env else "http://localhost:8000" return f"{env}/admin/{app_label}/{model}?action={action}&_selected_action={id}"

The generated link is:

PLAINTEXT
http://localhost:8000/admin/app/mymodel?action=process&_selected_action=591

However, when clicking the link, it only navigates to the model's changelist view in the admin. The objects are not pre-selected and the action is not applied as expected.

0

Comments 0

Answers 0

Views 69

0 Answers

Discussion

No comments yet.