diff --git a/cms/models.py b/cms/models.py index e6c42f2..96889f5 100644 --- a/cms/models.py +++ b/cms/models.py @@ -3,6 +3,7 @@ import swapper from django.db import models from django.urls import reverse from django.forms import TextInput, Select +from django.utils.text import slugify from django.utils.translation import gettext_lazy as _ from embed_video.fields import EmbedVideoField from polymorphic.models import PolymorphicModel @@ -101,6 +102,9 @@ class BaseSection(Numbered, PolymorphicModel): def number_with_respect_to(self): return self.page.sections.all() + def get_absolute_url(self): + return self.page.get_absolute_url() + '#' + slugify(self.title) + def __str__(self): if not self.pk: return str(_('New section')) diff --git a/cms/templates/cms/page.html b/cms/templates/cms/page.html index 80419a8..03994c4 100644 --- a/cms/templates/cms/page.html +++ b/cms/templates/cms/page.html @@ -6,6 +6,7 @@ {% block content %} {% for section in sections %} +
{% include_section section %} {% endfor %} diff --git a/cms/views.py b/cms/views.py index 657f7e4..d9eac72 100644 --- a/cms/views.py +++ b/cms/views.py @@ -224,7 +224,7 @@ class EditSection(UserPassesTestMixin, edit.ModelFormMixin, base.TemplateRespons if form.is_valid(): section = form.save() if section: - return HttpResponseRedirect(section.page.get_absolute_url()) + return HttpResponseRedirect(section.get_absolute_url()) elif self.page.sections.exists(): return HttpResponseRedirect(self.page.get_absolute_url()) else: