I am trying to generate a link that takes users to the Django Admin page for a specific model, with certain objects already selected and an action pre-filled in the dropdown menu.
Here’s what I’ve tried so far:
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 looks like this:
http://localhost:8000/admin/app/mymodel?action=process&_selected_action=591
However, when I click on the link, it only takes me to the changelist view of the model in the admin. The objects aren’t selected, and the action isn’t pre-filled.