Give each section it's own id for use in urls

(e.g., http://localhost/#give-me-snacks)
main
Jaap Joris Vens 2020-03-16 19:32:39 +01:00
rodzic 774e9e7379
commit 045b05a337
3 zmienionych plików z 6 dodań i 1 usunięć

Wyświetl plik

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

Wyświetl plik

@ -6,6 +6,7 @@
{% block content %}
{% for section in sections %}
<div id="{{section.title|slugify}}"></div>
{% include_section section %}
{% endfor %}

Wyświetl plik

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