2009-04-18 41 views
1

我正在嘗試使用Django站點地圖。Sitemaps中的優先問題

class BlogSiteMap(Sitemap): 
    """A simple class to get sitemaps for blog""" 

    changefreq = 'hourly' 
    priority = 0.5 

    def items(self): 
     return Blog.objects.order_by('-pubDate') 

    def lastmod(self, obj): 
     return obj.pubDate 

我的問題is..I想成立前3個博客對象的優先級爲1.0,他們的休息 爲0.5的優先級。我看了documentation,但是沒辦法。

任何幫助將是可觀的。提前致謝。

回答

1

我認爲你可以改變每個對象的優先級。這樣的例子:

def items(self): 
    for i, obj in enumerate(Blog.objects.order_by('-pubDate')): 
     obj.priority = i < 3 and 1 or 0.5 
     yield obj 

def priority(self, obj): 
    return obj.priority 
0

類似的東西可能工作:

def priority(self, obj): 
    if obj.id in list(Blog.objects.all()[:3].values_list('id')) 
     return 1.0 
    else: 
     return 0.5