2009-04-18 13 views
1

장고 사이트 맵을 사용하려고합니다.Sitemap의 우선 순위 문제

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 1.0 그들 중 나머지 0.5 우선 순위로 처음 3 블로그 객체의 우선 순위를 설정하고 싶었다.

나는 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