I have a blog site and i want to generate 2 sitemaps, one for posts and one for categories the code that i have :
sitemaps.py
from django.contrib.sitemaps import Sitemap
from .models import Post, Category
class PostSitemap(Sitemap):
priority = 0.5
def items(self):
posts = Post.objects.filter(is_published=True).order_by('-updated_at')
return posts
def lastmod(self, obj):
return obj.updated_at
class CategorySitemap(Sitemap):
priority = 0.5
def items(self):
categories = Category.objects.filter(
is_published=True).order_by('-updated_at')
return categories
def lastmod(self, obj):
return obj.updated_at
urls.py
from .sitemap import PostSitemap, CategorySitemap
from django.contrib.sitemaps.views import sitemap
sitemaps = {
'posts': PostSitemap,
'categories': CategorySitemap,
}
urlpatterns = [
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}),
]
Is the above code a proper way to create dynamic sitemaps with django ;