title: Peewee atomic updates complex logic
body: <p>I  need to update fields for a whole users table. It is stated in the <a href="http://docs.peewee-orm.com/en/latest/peewee/querying.html#atomic-updates" rel="nofollow noreferrer">docs</a> that I shouldn't iterate through all table records. But to calculate a new field value I need to perform calculations using loops, user's relations and other complex logic relied on a concrete model.</p>
  
  <p>I tried to include this calculations in the model's property, but I got:</p>
  
  <pre><code>peewee.InterfaceError: Error binding parameter 0 - probably unsupported type.
  </code></pre>
  
  <p><strong>Atomic update:</strong></p>
  
  <pre><code>    query = User.update(balance=(User.balance + User.partners_reward))\
      .where(User.deposit &gt;= 3)
  </code></pre>
  
  <p><strong>Model:</strong></p>
  
  <pre><code>class User(peewee.Model):
      deposit = peewee.DecimalField(default=0)
      balance = peewee.DecimalField(default=0)
  
      @property
      def partners(self):
          query = (
              User.select(User, Partnership)
                  .join(Partnership, JOIN.INNER, on=Partnership.invited)
                  .where(Partnership.referral == self.id)
          )
          partners = query.execute()
          return partners
  
  
      @property
      def partners_reward(self):
          partners = self.partners
          sum_reward = 0
          partner_reward = 0.02
  
          for partner in partners:
              reward = partner.deposit * partner_reward
              sum_reward += reward
  
          return sum_reward
  </code></pre>
  
  <p><strong>Prop description:</strong></p>
  
  <p>Each user has partners (other users invited by him) and depending on them he gets bonuses. So to accomplish the update I need to collect user partners using relations and then calculate the actual bonus using loops.</p>
  
  <p>Changing property to a method solves this, but I don't know how I can get access to a concrete user instance.</p>
  
  <p>So how can some complex logic be implemented in atomic updates or should I do it using loop as not recommended?</p>