Enhance session admin to show room names

This commit is contained in:
James Polley 2018-01-15 03:41:50 +11:00
parent 30e65e65a6
commit 8da6d18098
2 changed files with 14 additions and 2 deletions

View file

@ -62,6 +62,8 @@ class TrackAdmin(admin.ModelAdmin):
class SessionAdmin(admin.ModelAdmin): class SessionAdmin(admin.ModelAdmin):
model = Session, model = Session,
filter_vertical=["slots"] filter_vertical=["slots"]
list_display=("day","start","end","room_names")
list__filter=("slot__slotroom__room","day")
admin.site.register(Day) admin.site.register(Day)
admin.site.register( admin.site.register(

View file

@ -267,14 +267,24 @@ class Session(models.Model):
return role return role
return None return None
@property
def rooms(self):
return Room.objects.filter(slotroom__slot__in=self.slots.all()).distinct()
@property
def room_names(self):
return ', '.join(room.name for room in self.rooms)
def __str__(self): def __str__(self):
start = self.start() start = self.start()
end = self.end() end = self.end()
rooms = ', '.join(room.name for room in self.rooms)
if start and end: if start and end:
return "%s: %s - %s" % ( return "%s: %s - %s in %s" % (
self.day.date.strftime("%a"), self.day.date.strftime("%a"),
start.strftime("%X"), start.strftime("%X"),
end.strftime("%X") end.strftime("%X"),
rooms
) )
return "" return ""