Skip to content

Instantly share code, notes, and snippets.

@sehrishnaz
Created February 10, 2022 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sehrishnaz/da5bf900800404a1b3e2a6a1d81db108 to your computer and use it in GitHub Desktop.
Save sehrishnaz/da5bf900800404a1b3e2a6a1d81db108 to your computer and use it in GitHub Desktop.
Create Dynamic Sitemap in Django Using Multiple Models Slug
from django.contrib.sitemaps import Sitemap
from .models import Your_Model_Name
class MySitemap(Sitemap):
changefreq = "weekly"
priority = 0.8
protocol = 'http'
def items(self):
return Your_Model_Name.objects.all()
def lastmod(self, obj):
return obj.modified_date_field_goes_here
def location(self,obj):
return '/%s/%s' % (obj.foriegn_key_field.your_slug_field,obj.your_slug_field_goes_here)
@sehrishnaz
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment