Django Query - How to use the objects.filter results
<p>If I use the following code it works perfectly:</p>

<pre><code>campaignnoquery = UserSelection.objects.filter(user=349).order_by('-campaignno')[:1]

for x in campaignnoquery:
    test2 = x.campaignno
</code></pre>

<p>However, when I try:</p>

<pre><code>campaignnoquery = UserSelection.objects.filter(user=349).order_by('-campaignno')[:1]

test1 = campaignnoquery.campaignno
</code></pre>

<p>I get the following error:</p>

<pre><code> test1 = campaignnoquery.campaignno
AttributeError: 'QuerySet' object has no attribute 'campaignno'
</code></pre>

<p>I am sure it is something basic and I could just crack on with the one that worked but I am just intrigued on whats happening.</p>

<p>Many thanks in advance, Alan.</p>

<p>You are referencing the wrong object! </p>

<p>When looping through campaignnoquery, <strong><em>x</em></strong> becomes campaignnoquery[0], campaignnoquery[1], etc... </p>

<p>Try referencing it like this:</p>

<pre><code>test1 = campaignnoquery[0].campaignno
</code></pre>

python mysql django