Browse files

Started detail and edit views with slug field to Schedule

  • Loading branch information...
1 parent 77dc781 commit 0a4e626dfe9b5887291259849368dabf6c7d4043 @brosner brosner committed Aug 30, 2012
Showing with 41 additions and 0 deletions.
  1. +1 −0 symposion/schedule/models.py
  2. +9 −0 symposion/schedule/urls.py
  3. +31 −0 symposion/schedule/views.py
View
1 symposion/schedule/models.py
@@ -7,6 +7,7 @@
class Schedule(models.Model):
section = models.OneToOneField(Section)
+ slug = models.SlugField(unique=True)
class Day(models.Model):
View
9 symposion/schedule/urls.py
@@ -0,0 +1,9 @@
+from django.conf.urls.defaults import url, patterns
+
+
+urlpatterns = patterns("symposion.schedule.views",
+ url(r"^$", "schedule_detail", name="schedule_detail_singleton"),
+ url(r"^edit/$", "schedule_edit", name="schedule_edit_singleton"),
+ url(r"^(\w+)/edit/$", "schedule_detail", name="schedule_detail"),
+ url(r"^(\w+)/edit/$", "schedule_edit", name="schedule_edit"),
+)
View
31 symposion/schedule/views.py
@@ -0,0 +1,31 @@
+from django.shortcuts import render, get_object_or_404
+
+from symposion.schedule.models import Schedule
+
+
+def schedule_detail(request, slug=None):
+ qs = Schedule.objects.all()
+ if pk is None:
+ schedule = next(iter(qs), None)
+ if schedule is None:
+ raise Http404()
+ else:
+ schedule = get_object_or_404(qs, slug=slug)
+ ctx = {
+ "schedule": schedule,
+ }
+ return render(request, "schedule/schedule_detail.html")
+
+
+def schedule_edit(request, slug=None):
+ qs = Schedule.objects.all()
+ if pk is None:
+ schedule = next(iter(qs), None)
+ if schedule is None:
+ raise Http404()
+ else:
+ schedule = get_object_or_404(qs, slug=slug)
+ ctx = {
+ "schedule": schedule,
+ }
+ return render(request, "schedule/schedule_edit.html")

0 comments on commit 0a4e626

Please sign in to comment.