title: business logic in model defination or seperate service layer?
body: <p>I was wondering which is the correct way to use models(ORM) of mongonegine python.</p>
  
  <p>I have a coupon class which directly maps to mongodb json document.</p>
  
  <pre><code>class Coupon(Document):
      __collection__ = 'coupon'
  
      coupon = StringField()
      points = IntField()
  
      @property
      def increment(self):
          self.points += 1
  
      @property
      def decrement(self):
          self.points += 1
  </code></pre>
  
  <p>The thing that i find wrong with above is , we are binding <strong><em>behaviour</em></strong> to database access layer, which i think is not correct way of doing things <em>(I might be completely wrong).</em></p>
  
  <p>Another way <em>(Which I think makes more sense)</em> is delegating business logic to some other layer commonly called as <strong><em>service</em></strong> layer:</p>
  
  <p><strong><em>models.py</em></strong></p>
  
  <pre><code>class Coupon(Document):
      __collection__ = 'coupon'
  
      coupon = StringField()
      points = IntField()
  </code></pre>
  
  <p><strong><em>services.py</em></strong></p>
  
  <pre><code>from models import Coupon
  
  def increment_points(c_id):
     c_id.points+=1
  </code></pre>
  
  <p>I want to know which is the correct way of doing things(assuming we have lots of models).</p>
  
  <p><strong><em>Question: should we bind behaviors to models or use a service layer for business logic?</em></strong></p>
  
  <p><strong>NOTE</strong>: I have added tag <code>python</code> because I have seen many people binding behaviours and business logic to the DB access layer in their codebases.services are rarely heard of in any of the tutorials about python web frameworks. but its very common in Java and PHP.</p>