Django: Identify the urls that provide duplicate content and set a canonical link
<p>models.py</p>

<pre><code>class People(models.Model):
    name = models.CharField(max_length=16)
    meters_away = models.IntegerField()
</code></pre>

<p>Lets populate the db:</p>

<pre><code>&gt;&gt;&gt; from people.models import People
&gt;&gt;&gt; a = People()
&gt;&gt;&gt; a.name = 'George'
&gt;&gt;&gt; a.meters_away = 15
&gt;&gt;&gt; a.save()
&gt;&gt;&gt; b = People()
&gt;&gt;&gt; b.name = 'Jim'
&gt;&gt;&gt; b.meters_away = 10
&gt;&gt;&gt; b.save()
</code></pre>

<p>Supposing that we have a url that returns all people in a range of x meters: </p>

<p><code>http://example.com/range/&lt;meters&gt;</code></p>

<p>This url scheme accepts 3 hits as follows:</p>

<ol>
<li><code>http://example.com/range/20</code></li>
<li><code>http://example.com/range/30</code></li>
<li><code>http://example.com/range/40</code></li>
</ol>

<p>Those hits will create the following queries:</p>

<pre><code>&gt;&gt;&gt; hit1 = People.objects.filter(meters_away__lt=20)
&gt;&gt;&gt; hit2 = People.objects.filter(meters_away__lt=30)
&gt;&gt;&gt; hit3 = People.objects.filter(meters_away__lt=40)
</code></pre>

<p>Where:</p>

<pre><code>&gt;&gt;&gt; list(hit1) == list(hit2) == list(hit3)
&gt;&gt;&gt; True
</code></pre>

<p>This means that <code>example.com</code>, will serve 3 different urls with the same content.</p>

<p>From a SEO point of view, how could all the possible urls (meters: 21, 22, 23, 24, 30, 40 etc) be filtered in a way that a canonical url is appended to them?</p>