title: How to run a forloop in django views.py?
body: <p>I want to iterate over a queryset and if there is a new user added, I want to add some points for a specific user. To be more clear with what i am building: =&gt; I am writing a referral system logic in django.</p>
  <p>The referral system works fine now, but what i want to implement is this. When i refer a user which are &quot;<strong>user 2</strong>&quot; and &quot;<strong>user 3</strong>&quot;, it is stored that I have referred <strong>two users</strong>, now I have also implemented a way to know if &quot;user 2&quot; or &quot;user 3&quot; which are referred by me: have gotten a new user referred by them (&quot;user 2&quot; or &quot;user 3&quot;).</p>
  <p>Now what i want to achieve is this, when there is a new user from <strong>&quot;user 2&quot;</strong> or <strong>&quot; user 3 &quot;</strong> I want to add a some points to the <strong>&quot;user 1&quot;</strong> which referred the two user <em>(&quot;<strong>user 2</strong>&quot; and &quot;<strong>user 3</strong>&quot;)</em> that referred the new users.</p>
  <p>I am thinking of using a forloop to iterate over the <code>second_level_recommended</code>, then add the point to the profile but it doesn't seem to work or maybe the code that I wrote was wrong. This is the code that I wrote for the for-loop:</p>
  <pre><code># for i in second_level_recommended:
      profile = Profile.objects.filter(recommended_by=request.user)
      profile.indirect_sign_up = profile.indirect_sign_up =+ 200
  </code></pre>
  <p>This is the code to check for the new users that &quot;<strong>user 2</strong>&quot; and &quot;<strong>user 3</strong>&quot; have referred belonging to <strong>&quot;user 1&quot;</strong></p>
  <p>views.py</p>
  <pre><code>my_recommended = Profile.objects.filter(recommended_by=request.user).values_list('user__id', flat=True)
  second_level_recommended=Profile.objects.filter(recommended_by__in=my_recommended)
  </code></pre>
  <p>Then there is a forloop in the templates to display the <code>second_level_recommended</code></p>
  <p>NOTE: There is a <code>Profile</code> model which have these fields in it</p>
  <pre><code>class Profile(models.Model):
      user = models.OneToOneField(User, ...)
      ...
      code = models.CharField(max_length=100, ...)
      recommended_by = models.ForeignKey(User, ...)
  </code></pre>