B
B
blackbb2020-06-27 19:48:14
Django
blackbb, 2020-06-27 19:48:14

How to correctly compose the path of the page model if there are child pages?

There is a page model

class Page(models.Model):
  """Модель Страницы"""
  title = models.CharField(max_length=20, verbose_name='Заголовок')
  slug = models.SlugField(unique=True, verbose_name='Дружественный URL')
  parent = models.ForeignKey('self', on_delete=models.CASCADE, blank=True, null=True, related_name='children', verbose_name='Родительская страница')

views.py
class PageView(DetailView):
  model = Page
  context_object_name = 'page'
  template_name = 'core/page.html'
  queryset = Page.objects.filter(published=True, hidden_menu=False)

urls.py I need the slug of the parent to be added to the slug of the child pages (if has parent musite.ru/parent/children), how can I implement this? More precisely, I understood how to implement it, but how to add urls.py for processing.
path('<slug>/', PageView.as_view(), name='page'),

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question