title: Django model field by variable
body: <p>Quick question. I'm trying yo access one of the fields of a model using a variable.</p>
  
  <pre><code>class ExampleModel(models.Model):
        the_field = models.CharField()
        the_field_two = models.CharField()
  </code></pre>
  
  <p>How would access the field dynamically? I tried:</p>
  
  <pre><code>model = ExampleModel.objects.get(pk=1)
  fieldtoget = 'the_field'
  test_var = model[fieldtoget]
  </code></pre>
  
  <p>But it doesn't seem to work, any ideas how I would do this?</p>
  
  <p><strong>Update:</strong> Thought I'd update my question. I'm trying to write a function (as part of larger function) that can not only get the value of the field but also update it from a variable fieldname. For example:</p>
  
  <pre><code>model[fieldtoget] = 'yo'
  model.save()
  </code></pre>
  
  <p>In PHP you can use the {} wrapper - <code>$model{$fieldtoget}</code> - as an example, for dynamic variable names was hoping there was something similar in python :)</p>
  
  <p>Cheers</p>