Getting first view up and running.

This commit is contained in:
Víðir Valberg Guðmundsson 2016-07-13 22:37:20 +02:00
parent 5c00934027
commit 3cf837e8e9
7 changed files with 66 additions and 7 deletions

View file

@ -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)),
]

View file

@ -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
)

View file

@ -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)

View file

@ -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

View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
</body>
</html>

View file

@ -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')
]

View file

@ -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