class Page(MPTTModel):
"""Base model of Page"""
seo_title = models.CharField(max_length=150, blank=True, verbose_name=_('SEO title'))
seo_description = models.CharField(max_length=170, blank=True, verbose_name=_('SEO description'))
title = models.CharField(max_length=300, verbose_name=_('Title'))
slug = models.SlugField(unique=True, verbose_name=_('URL address'))
content = tinymce_models.HTMLField(verbose_name=_('Content'), blank=True)
parent = TreeForeignKey('self', on_delete=models.CASCADE, blank=True, db_index=True, null=True, related_name='children',
verbose_name=_('Parent'))
menu_top = Page.objects.filter(in_menu_top=True, parent=None)
<ul>
{% recursetree menu_top %}
<li {% if not node.is_leaf_node %}class="dropdown"{% endif %}>
<a {% if not node.is_leaf_node %} class='drop-down'{% else %}href="{{node.slug}}"{% endif %}>
{% if not node.is_leaf_node %}
<div>
{{children}}
</div>
{% endif %}
</li>
{%endrecursetree%}
</ul>
from django.db import models
from mptt.models import MPTTModel, TreeForeignKey
class Page(MPTTModel):
title = models.CharField(max_length=300, verbose_name=_('Title'))
slug = models.SlugField(unique=True, verbose_name=_('URL address'))
content = tinymce_models.HTMLField(verbose_name=_('Content'), blank=True)
parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children')
class MPTTMeta:
order_insertion_by = ['title']
def get_fieldsets(self, request, obj):
fieldsets = super().get_fieldsets(request, obj)
if obj.slug == 'contact':
self.fieldsets += (
('SEO', {
'fields': ('seo_title','seo_description')
}),
('Основные настройки', {
'fields': ('title', 'slug', 'content', 'template'),
}),
)
return fieldsets