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.
Asked 3 months ago by StarPioneer357
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:
PYTHONdef 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:
PLAINTEXThttp://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.
Comments 0
•Answers 0
•Views 69
No comments yet.