Add bulk "Set status to Not Started" action to EvaluationAdmin#7
Conversation
Agent-Logs-Url: https://github.com/janelia-cellmap/frx-challenges/sessions/0f977f9a-a80a-4a83-add9-0ff6313f03df Co-authored-by: rhoadesScholar <37990507+rhoadesScholar@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a Django admin bulk action to EvaluationAdmin so administrators can reset the status of multiple Evaluation records to NOT_STARTED in one operation.
Changes:
- Added a
set_status_not_startedadmin action toEvaluationAdmin. - Registered the action in the admin actions dropdown and displayed a success message after execution.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def set_status_not_started(self, request, queryset): | ||
| updated = queryset.update(status=Evaluation.Status.NOT_STARTED) | ||
| self.message_user(request, f"{updated} evaluation(s) set to Not Started.") |
There was a problem hiding this comment.
Using queryset.update(...) will bypass Model.save(), so Evaluation.last_updated (auto_now) won’t be bumped and any model signals won’t run. If you expect the admin bulk reset to reflect as a fresh update (and since last_updated is displayed and used for latest("last_updated")), consider also updating last_updated explicitly (e.g., to timezone.now()) or iterating and calling save() if signal behavior is required.
There was a problem hiding this comment.
Fixed in 70e18e4. The queryset.update() call now also sets last_updated=timezone.now() explicitly, ensuring the timestamp is bumped correctly since auto_now fields are bypassed by bulk queryset updates.
|
@copilot Currently there is a "Delete selected evaluations" option under the actions menu, but I'm not seeing that in the Evaluation admin. Are you sure you got everything correct? |
Agent-Logs-Url: https://github.com/janelia-cellmap/frx-challenges/sessions/9ce46de1-a618-4580-947e-4f4973ceff5b Co-authored-by: rhoadesScholar <37990507+rhoadesScholar@users.noreply.github.com>
The code is correct — the action is properly registered via |

Django admin
EvaluationAdminlacked any custom actions, making it impossible to bulk-resetEvaluationrecords without editing each one individually.Changes
frx_challenges/web/admin.py: Addedset_status_not_startedaction toEvaluationAdminactions = ["set_status_not_started"]@admin.action(description="Set status to Not Started")for the dropdown labelqueryset.update(status=Evaluation.Status.NOT_STARTED)for a single-query bulk updateself.message_userOriginal prompt
Problem
The Django admin
EvaluationAdmin(atfrx_challenges/web/admin.py) has no custom actions in its Actions dropdown. Users need to be able to select multipleEvaluationrecords and bulk-reset their status toNOT_STARTED.Solution
Add a custom admin action
set_status_not_startedtoEvaluationAdmininfrx_challenges/web/admin.py:actions = ["set_status_not_started"]to theEvaluationAdminclass.@admin.action(description="Set status to Not Started")decorator.queryset.update(status=Evaluation.Status.NOT_STARTED)and then callself.message_user(request, ...)to display a success message.Target file
frx_challenges/web/admin.pyUpdated
EvaluationAdminclass should look like:No other classes or logic should be changed.
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: How can I add "actions" do this Action drop down menu? I can select all records, and I want to be able to set the status for all the selected records to "Not Started" using the actions dropdown.
Assistant: To add a custom action to the Django admin Actions dropdown, you need to define an action function and register it on the
EvaluationAdminclass infrx_challenges/web/admin.py.Here's exactly what to add:
Key changes explained:
actions = ["set_status_not_started"]— Tells Django admin to include this method in the Actions dropdown.@admin.action(description="...")— Sets the label shown in the dropdown ("Set status to Not Started").queryset.update(...)— Efficiently updates all selected records in a single DB query.self.message_user(...)— Shows a success banner at the top of the page after the action runs.After saving the file, the dropdown will show "Set status to Not Started" as an option. Select your records, choose it, and click Go.
Would you like me to open a PR with this change?
User: Yes please.
Assistant: I've kicked off the coding agent to create the PR! It will add the
set_status_not_startedaction toEvaluationAdmininfrx_challenges/web/admin.py. Once the PR is open, you'll be able to review the change before merging. I'll let you know the link as soon as it's available.This pull request was created from Copilot chat.