Add admin action to update slot names

* The slot object updates its name every time it is saved
* But sometimes its slotrooms are changed underneath it, and so the
  name can become out of date
* This method is a simple way of updating the names for all the slots
This commit is contained in:
James Polley 2018-01-10 21:10:52 +11:00
parent 9a25ca1754
commit f99765ca0b

View file

@ -25,12 +25,19 @@ class SlotRoomInline(admin.TabularInline):
extra = 1
def update_slot_names(modeladmin, request, queryset):
for slot in queryset:
slot.save()
update_slot_names.short_description = "Update slot names"
class SlotAdmin(admin.ModelAdmin):
list_filter = ("day", "kind","exclusive","slotroom__room")
list_display = ("day", "start", "end", "kind", "room_names",
"content_override","exclusive")
list_editable = ("exclusive",)
list_editable = ("exclusive","kind","start","end")
inlines = [SlotRoomInline]
actions = [update_slot_names]
def room_names(self, slot):
return ", ".join(room.name for room in slot.rooms.all())