WebFaction
Community site: login faq

Is it possible to unify sitemaps from multiple model files into 1 url?

I have these two in one file:

class CompanySitemap(Sitemap):
    def items(self):
        return Company.objects.all()

class FlatPageSitemap(Sitemap):
    def items(self):
        return FlatPage.objects.all()

SITEMAPS = {'Company': CompanySitemap, 'flatpage': FlatPageSitemap,}

Then I have a separate models file with a 3rd class I'd like added to the sitemap:

class ArticleSitemap(Sitemap):
    def items(self):
        return Article.active.all()

SITEMAPS = {'Article': ArticleSitemap,}

Here is my URL. I'd like for the sitemap to generate from all 3 classes, not just the top 2. Is it possible?

urlpatterns += patterns('', (r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': SITEMAPS }),)

Thanks.

asked 18 Feb '11, 14:04

pythondjango
161810
accept rate: 0%


Yes. In your urls.py import those classes. Create the SITEMAPS dictionary as you have done in your urls.py. The url you have specified should work just fine then.

Make sure to use: from app.sitemap import CompanySitemap

permanent link

answered 18 Feb '11, 15:07

bmeyer71 ♦♦
1.5k3613
accept rate: 33%

edited 18 Feb '11, 15:18

I'm having trouble constructing the dictionary. Receiving the error: "unhashable type: 'dict'".

urlpatterns += patterns('', (r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': SITEMAPS }), ('mysite.wiki.models', {'sitemaps': SITEMAPS }),)

(18 Feb '11, 15:24) pythondjango

Create your urls.py with the following:
from mysite.models import CompanySitemap
from mysite.models import FlatPageSitemap
from other.models import ArticleSitemap

sitemaps = {
'company': CompanySitemap,
'flatpage': FlatPageSitemap,
'article': ArticleSitemap,
}

Add your url: (r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps }),

(18 Feb '11, 16:27) bmeyer71 ♦♦

You're the man. I understand after seeing this. Thanks a bunch, off-to-the-next-error!

(18 Feb '11, 20:42) pythondjango
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×910
×2

question asked: 18 Feb '11, 14:04

question was seen: 3,787 times

last updated: 18 Feb '11, 20:42

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM