2014-09-21 90 views
0

我想爲我的模型實現網站地圖。但它只顯示任一模型的鏈接。我必須評論該診所顯示的醫生和副verca的鏈接。django 1.6網站地圖不能正常工作

這裏有models.py

class Clinic(models.Model): 
    name = models.CharField(max_length=500) 
    slug = models.CharField(max_length=200, blank = True, null = True, unique = True) 
    contact_no = models.IntegerField() 
    submitted_on = models.DateTimeField(auto_now_add=True, null = True, blank = True) 

    def save(self, *args, **kwargs): 
     self.slug = slugify(self.name) 
     super(Clinic, self).save(*args, **kwargs) 

    def get_absolute_url(self): 
     from django.core.urlresolvers import reverse 
     return reverse('meddy1.views.clinicProfile', args=[str(self.slug)]) 

    def __unicode__(self): 
     return u"%s %s" % (self.name, self.contact_no) 

class Doctor(models.Model): 
    name = models.CharField(max_length=1300) 
    title = models.CharField(max_length=1300, null = True, blank = True) 
    specialization = models.ForeignKey(Specialization) 
    clinic = models.ForeignKey(Clinic) 
    education1 = models.CharField(max_length=1300) 

    def __unicode__(self): 
     return u"%s %s" % (self.name, self.specialization) 

    def get_absolute_url(self): 
     from django.core.urlresolvers import reverse 
     return reverse('meddy1.views.showDocProfile', args=[str(self.id)]) 

是否有什麼關係的事實,診所是在醫生型號外鍵?

urls.py

from django.conf.urls import patterns, include, url 
from django.contrib import admin 
from django.views.generic import TemplateView 
from meddy1.models import * 
from django.contrib.sitemaps import GenericSitemap 

from django.contrib.sitemaps.views import sitemap 

from meddy1.sitemap import * 

from meddy1 import views 


admin.autodiscover() 


info_dict = { 
    'queryset': Doctor.objects.all(), 
    # 'queryset': Clinic.objects.all(), 
    'date_field': 'submitted_on', 
} 

sitemaps = { 
    'doctor': GenericSitemap(info_dict, priority=0.6), 
    'static': StaticViewSitemap, 
    'clinic': GenericSitemap(info_dict, priority=0.6), 
} 

urlpatterns = patterns('', 
    url(r'^', include('meddy1.urls')), 
    url(r'^', include('django.contrib.auth.urls')), 
    url(r'^admin/', include(admin.site.urls)), 
    url(r'^robots\.txt$', TemplateView.as_view(template_name="meddy1/robots.txt")), 
    url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}), 

sitemap.py

from django.contrib.sitemaps import Sitemap 
from django.core.urlresolvers import reverse 

from meddy1.models import * 

class DoctorSitemap(Sitemap): 
    changefreq = "weekly" 
    priority = 0.5 

    def items(self): 
     return Doctor.objects.all() 

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


class ClinicSitemap(Sitemap): 
    changefreq = "weekly" 
    priority = 0.5 

    def items(self): 
     return Clinic.objects.all() 

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

class StaticViewSitemap(Sitemap): 
    priority = 0.5 
    changefreq = 'weekly' 

    def items(self): 
     return ['index', 'about', 'privacy','terms', 'login', 'signup'] 

    def location(self, item): 
     return reverse(item) 

有了上面的代碼顯示了靜態頁面和醫生模型站點地圖鏈接。

回答

1

您正在使用站點地圖都同樣字典,這就是爲什麼你看到了同樣的鏈接。 GenericSitemap是使用給定字典的queryset屬性的快捷方式。

但我也想知道爲什麼你不使用你的擴展地圖類?