add: динамическое создание sitemap.xml

This commit is contained in:
2026-01-29 22:33:33 +03:00
parent a95d677bb7
commit 7e7d0a7d49
3 changed files with 30 additions and 8 deletions

View File

@@ -0,0 +1,14 @@
from django.contrib.sitemaps import Sitemap
from .models import Post
class PostSitemap(Sitemap):
changefreq = "weekly" # Как часто меняются страницы
priority = 0.9 # Приоритет (от 0.0 до 1.0)
def items(self):
"""Возвращает все опубликованные посты и страницы."""
return Post.objects.filter(is_published=True)
def lastmod(self, obj):
"""Возвращает дату последнего изменения."""
return obj.published_at # Или можно добавить поле updated_at