Django filter-save QuerySet
<p>I've a django model:-</p>

<pre><code>class ModelA(models.Model):
    flag = models.BooleanField(default=True)
</code></pre>

<p>Next, I query it:- </p>

<p><code>obj = ModelA.objects.filter(flag=True)</code></p>

<p>Now, I change the <code>flag</code> of first object.</p>

<pre><code>obj1 = obj[0]
obj1.flag = False
obj1.save()
</code></pre>

<p>Now, when I get <code>obj[0]</code> again, it returns me the <code>2nd object</code> of the filtered query. <strong>Why?</strong></p>

<p>Because the first object does not match anymore the filtered queryset, you can't find it in the <code>obj</code> pointer. If you want to clone the queryset to another variable you can use <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#values-list" rel="nofollow">values_list</a>.</p>

python django django-queryset