title: model and instance methods: session aware (sqlalchemy)
body: <p>So, using and learning with sqlalchemy.</p>
  
  <p>I have an instance, I need to get a value. If that value exists, return it.
  If not calculate and return it.</p>
  
  <p>Invariably someone will say 'you're doing it wrong' and input on improvement is appreciated in general.
  However I am looking into how I can do this without explicitly having to manage the session, because what I'm working on is starting to grow, and constantly managing the session for when I want to update an instance is problematic. It makes me think that I <em>am</em> in fact doing it wrong.</p>
  
  <p>So how do I fix the method below to not have manage the session explicitly? </p>
  
  <pre><code>def method(self, session):
          if self.i_needed_this is None:
              self.i_needed_this = calculate(calcutron)
              session.add(self)
              session.commit()
              return self.i_needed_this                        
          else:
              return self.i_needed_this
  </code></pre>
  
  <p>Maybe this question should be titled 'making instances session aware so I'm not always explicitly managing it', and if it's a dumb question, at least show me why with examples and point me to where others have  asked better.</p>
  
  <p>Edit: apparently, importing the session I'm using works, and it is available, so maybe its a non issue or a future one for when I am more skilled with sqlalchemy.</p>