How to chain a queryset together in Django correctly
<p>Using the example below, I'm trying to use a queryset and append/chain filters together. To my understanding last <code>queryset.count()</code> should have just 1 instance, but it always had the original 10 in it.  </p>

<p>Expected output of last <code>queryset.count()</code> is 1:</p>

<pre><code># Set a default queryset.
def get_queryset(self, *args, **kwargs):
    queryset = super(UserMixin, self).get_queryset(*args, **kwargs)
    queryset.count() # 10 instacnes
    queryset.filter(id=1)
    queryset.count() # 10 instacnes excpeted 1
</code></pre>

<p>I can solve this problem I think by:</p>

<pre><code>queryset = queryset.filter(id=1)
</code></pre>

<p>Is this the correct way or there a way to chain them correctly where I can add the queryset object around?</p>

<p>You never assign the filter to anything so it doesn't update it</p>

<pre><code> queryset = queryset.filter(id=1)
</code></pre>

<p>Yes this is the correct way because you are creating a new query, otherwise you need to call the count on the end of the previous filter call</p>

python django