title: Django sitemap for multilanguage website posts filter
body: <p>I try to seperate my post on lang. in sitemap. but But for example, if there are 3 languages (en,fr,de), each post three added in sitemap.</p>
  
  <p>example
  my_sample_post_english in db language option "en"
  my_sample_post_french in db language option "fr"</p>
  
  <p>my sitemap create like this; </p>
  
  <pre><code>&lt;url&gt;
  &lt;loc&gt;http://127.0.0.1:8000/en/post/vote/my_sample_post_english&lt;/loc&gt;
  &lt;lastmod&gt;2020-05-19&lt;/lastmod&gt;
  &lt;priority&gt;0.5&lt;/priority&gt;
  &lt;/url&gt;
  
  &lt;url&gt;
  &lt;loc&gt;http://127.0.0.1:8000/fr/post/vote/my_sample_post_english&lt;/loc&gt;
  &lt;lastmod&gt;2020-05-19&lt;/lastmod&gt;
  &lt;priority&gt;0.5&lt;/priority&gt;
  &lt;/url&gt;
  
  &lt;url&gt;
  &lt;loc&gt;http://127.0.0.1:8000/de/post/vote/my_sample_post_english&lt;/loc&gt;
  &lt;lastmod&gt;2020-05-19&lt;/lastmod&gt;
  &lt;priority&gt;0.5&lt;/priority&gt;
  &lt;/url&gt;
  </code></pre>
  
  <p>how can i filter post for languages? i want like this;</p>
  
  <pre><code>&lt;url&gt;
  &lt;loc&gt;http://127.0.0.1:8000/en/post/vote/my_sample_post_english&lt;/loc&gt;
  &lt;lastmod&gt;2020-05-19&lt;/lastmod&gt;
  &lt;priority&gt;0.5&lt;/priority&gt;
  &lt;/url&gt;
  
  &lt;url&gt;
  &lt;loc&gt;http://127.0.0.1:8000/fr/post/vote/my_sample_post_french&lt;/loc&gt;
  &lt;lastmod&gt;2020-05-19&lt;/lastmod&gt;
  &lt;priority&gt;0.5&lt;/priority&gt;
  &lt;/url&gt;
  
  &lt;url&gt;
  &lt;loc&gt;http://127.0.0.1:8000/de/post/vote/my_sample_post_deutsch&lt;/loc&gt;
  &lt;lastmod&gt;2020-05-19&lt;/lastmod&gt;
  &lt;priority&gt;0.5&lt;/priority&gt;
  &lt;/url&gt;
  </code></pre>
  
  <p>url.py</p>
  
  <pre><code>urlpatterns += i18n_patterns(
      ...
      path('sitemap.xml', sitemap, {'sitemaps': sitemaps},
       name='django.contrib.sitemaps.views.sitemap'),
      ...
  ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  </code></pre>
  
  <p>sitemaps.py</p>
  
  <pre><code>class BlogSitemap(Sitemap):
      priority = 0.5
      # this generates urls per language
      i18n = True
  
      def items(self):
          posts= Post.objects.filter(private=False)
          for b in posts:
              if b.language == 'en':
                  b.language = str('en/') + b.language
              if b.language == 'fr':
                  b.language = str('fr/') + b.language
              if b.language == 'de':
                  b.language = str('de/') + b.language
          return posts
  
      def lastmod(self, obj):
          return obj.created_date
  </code></pre>
  
  <p>model.py</p>
  
  <pre><code>class Post(models.Model):
      title = models.CharField(max_length=350,verbose_name="PostTitle")
      slug = models.SlugField(unique=True, max_length=353, null=True)
      language = models.CharField(max_length=30, choices=settings.LANGUAGES, default="en")
      private = models.BooleanField(blank=True, default=False, verbose_name="Private Post")
  
      def get_absolute_url(self):
          return reverse('post:addVote', args=[str(self.slug)])
  </code></pre>