Reputation: 1473
I have a small app for a local hockey league, I wanted to know if it was possible to write an action on the admin of the games, so that when I check 2 games, it exchanges the teams that are about to play.
Example team A vs team B -- team C vs team D, if I swap this with the action menu it should be team C vs team B -- team A vs Team D
Thats the general idea... anyone has any suggestion? or ideas on how to achieve this!
Thank you all!
Upvotes: 0
Views: 161
Reputation: 691
You have to define a method like this:
def exchange_team(modeladmin, request, queryset):
if queryset.count() == 2:
#your interchange code...
And reference it in your admin class:
class TeamAdmin(admin.ModelAdmin):
...
actions = ['exchange_team']
admin.register(Team, TeamAdmin)
Upvotes: 1