Hi,
I'm setting up some Django sitemaps. It works really well for all the objects I have, but I'm curious about how I should do it if I'd like to put something in the sitemap that has no object associated with it.
For instance, I have a category listing, and I can just return a queryset of all categories. URLs would be example.com/cats/12 or what have you. I also have a sort of pseudo root category that isn't associated with a category object. That page (example.com/cats/) is just a view that includes all sub categories with no parent, and a list of products. Point is, I can't use get_absolute_url because there is no "root" object. My solution was to get the queryset as a list, add a "None" object, then get the appropriate URL:
class CatsSitemap(Sitemap):
changefreq = "weekly"
priority = 0.4
def items(self):
cats = list(Category.objects.all())
cats.append(None)
return cats
def location(self, obj):
if(obj != None):
return reverse('cats_sub_category', args=[obj.pk])
else:
return reverse('cats_root')
Does anyone see a problem with this? Will returning them as a list kill performance? Realistically we'll have perhaps hundreds of categories, but probably not many more than that. Too much?