from django.db import models
from django.utils.text import slugify
+from django.core.urlresolvers import reverse
from karmaworld.settings.manual_unique_together import auto_add_check_unique_together
natural_key.dependencies = ['courses.department']
def get_absolute_url(self):
- """ return url based on school slug and self slug """
- return u"/{0}/{1}".format(self.school.slug, self.slug)
+ """ return url based on urls.py definition. """
+ return reverse('course_detail', kwargs={'slug':self.slug})
def save(self, *args, **kwargs):
""" Save school and generate a slug if one doesn't exist """
return context
def get_success_url(self):
- """ On form submission success, redirect to what url """
- return u'/{school_slug}/{course_slug}'.format(
- school_slug=self.object.school.slug,
- course_slug=self.object.slug)
+ """ On success, return url based on urls.py definition. """
+ return self.object.get_absolute_url()
def form_invalid(self, form, **kwargs):
""" override form_invalid to populate object_list on redirect """
url(r'^search/$', NoteSearchView.as_view(), name='note_search'),
# VIEW for displaying a single Course
- url(r'^' + SLUG.format('school_') + '/' + SLUG.format('') + '/$',
+ url(r'^course/' + SLUG.format('') + '/$',
CourseDetailView.as_view(), name='course_detail'),
## NOTE MODEL