title: How to convert string variables from one class to flask-sqlalchemy database?
body: <p>so, I created this small example to illustrate my question:</p>
  <p>I have a (Flask) application. In this example, a user can upload files that have text about a certain fruit. I extract that information and save it in a class to process further, like this:</p>
  <pre><code>class uploaded_fruits():
       def __init__(self, fruit, taste):
            self.fruit = fruit
            self.taste = taste
  </code></pre>
  <p>I also save the information in a sqlalchemy database, which I use to store the information for the frontend:</p>
  <pre><code>class fruits(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      fruit = db.Column(db.String(10))
      taste = db.Column(db.String(50))
      edit = LinkCol('Edit', 'edit', url_kwargs=dict(id='id'))
  </code></pre>
  <p>In the <code>uploaded_fruits(</code>) I store information that another function uses, and in de <code>fruits()</code> database I store information in a way that the user understands. For example, for the sweet taste of fruit I use &quot;<code>SW</code>&quot; in <code>uploaded_fruits()</code> and &quot;<code>Sweet</code>&quot; in <code>fruits()</code>, I store this conversion in a dictionary like this:</p>
  <pre><code>Taste_list = {
      &quot;Sweet&quot; : &quot;SW&quot;,
      &quot;Sour&quot; : &quot;SO&quot;,
      &quot;Salty&quot; : &quot;SA&quot;,
      &quot;Bitter&quot; : &quot;BI&quot;,
  }
  </code></pre>
  <p>So for example, if I would have:</p>
  <pre><code>apple = uploaded_fruits(&quot;apple&quot;, &quot;SW&quot;)
  pear = uploaded_fruits(&quot;Pear&quot;, &quot;SW&quot;)
  </code></pre>
  <p>I would like to insert this in the <code>fuits()</code> database like this:</p>
  <pre><code>class fruits(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      fruit = [&quot;apple&quot;, &quot;pear&quot;]
      taste = [&quot;Sweet&quot;, &quot;Sweet&quot;]
  </code></pre>
  <p>But I can't seem to do it right. I tried this:</p>
  <pre><code>for fruit in uploaded_fruits:
          analyzed_fruits = fruits()
          analyzed_fruits.fruit = fruit.fruit
  
          # When the text analyses does not conclude on a taste 
          if fruit.taste is None:
              analyzed_fruit.taste = &quot;Taste unknown 1&quot;
          else:
              match_taste = fruit.taste
  
              for key, value in Taste_list.items():
                  if match_taste in value:
                      analyzed_fruit.taste = key
                  else:
                      analyzed_fruit.taste = &quot;Taste unknown 2&quot;
  
           db.session.add(analyzed_file)
           db.session.commit()
  </code></pre>
  <p>But all I now get is <code>&quot;Taste Unknown 2&quot;</code>, so it seems not able to match in for some reason. Could someone help me?</p>