diff --git a/bornhack/urls.py b/bornhack/urls.py index 5cdd323b..433c95eb 100644 --- a/bornhack/urls.py +++ b/bornhack/urls.py @@ -78,6 +78,10 @@ urlpatterns = [ r'^villages/', include('villages.urls', namespace='villages') ), + url( + r'^program/', + include('program.urls', namespace='program') + ), url(r'^accounts/', include('allauth.urls')), url(r'^admin/', include(admin.site.urls)), ] diff --git a/camps/models.py b/camps/models.py index ea38b8c2..bcbeb731 100644 --- a/camps/models.py +++ b/camps/models.py @@ -60,6 +60,7 @@ class Day(CreatedUpdatedModel, UUIDModel): class Meta: verbose_name = _('Day') verbose_name_plural = _('Days') + ordering = ['date'] camp = models.ForeignKey( 'camps.Camp', @@ -74,9 +75,9 @@ class Day(CreatedUpdatedModel, UUIDModel): ) def __str__(self): - return '{} {}'.format( - self.date, - self.camp + return '{} ({})'.format( + self.date.strftime('%A'), + self.date ) diff --git a/program/admin.py b/program/admin.py index 16c4604d..f85fec27 100644 --- a/program/admin.py +++ b/program/admin.py @@ -10,7 +10,19 @@ class EventTypeAdmin(admin.ModelAdmin): @admin.register(Event) class EventAdmin(admin.ModelAdmin): - pass + list_display = [ + 'title', + 'event_type', + 'get_days', + 'start', + 'end' + ] + + def get_days(self, obj): + return ', '.join([ + str(day.date.strftime('%a')) + for day in obj.days.all() + ]) @admin.register(Speaker) diff --git a/program/models.py b/program/models.py index 6a9acbe6..d0d379b6 100644 --- a/program/models.py +++ b/program/models.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals from django.db import models -from django.contrib.postgres.fields import DateTimeRangeField from utils.models import CreatedUpdatedModel @@ -10,6 +9,9 @@ class EventType(CreatedUpdatedModel): name = models.CharField(max_length=100) slug = models.SlugField() + def __str__(self): + return self.name + class Event(CreatedUpdatedModel): """ Something that is on the program. """ @@ -20,6 +22,9 @@ class Event(CreatedUpdatedModel): start = models.TimeField() end = models.TimeField() + def __str__(self): + return self.title + class Speaker(CreatedUpdatedModel): """ Person anchoring an event. """ @@ -31,3 +36,6 @@ class Speaker(CreatedUpdatedModel): related_name='speakers', related_query_name='speaker' ) + + def __str__(self): + return self.name diff --git a/program/templates/program.html b/program/templates/program.html new file mode 100644 index 00000000..de155ea5 --- /dev/null +++ b/program/templates/program.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file diff --git a/program/urls.py b/program/urls.py index a185476a..be495518 100644 --- a/program/urls.py +++ b/program/urls.py @@ -2,5 +2,5 @@ from django.conf.urls import url from views import * urlpatterns = [ - url(r'^$', ProgramIndexView.as_view(), name='index') + url(r'^$', ProgramView.as_view(), name='index') ] diff --git a/program/views.py b/program/views.py index 28002783..cf759bf9 100644 --- a/program/views.py +++ b/program/views.py @@ -1,2 +1,26 @@ -from django.shortcuts import render +from collections import OrderedDict + +from django.views.generic import ListView + +from camps.models import Day +from . import models + + +class ProgramView(ListView): + model = models.Event + template_name = 'program.html' + + def get_context_data(self, **kwargs): + context = super( + ProgramView, self + ).get_context_data(**kwargs) + + days = Day.objects.all() + + context['days'] = OrderedDict([ + (day, self.get_queryset().filter(days__in=[day])) + for day in days + ]) + + return context