title: Flask Python REST API set optional JSON param when receiving POST
body: <p>I'm building a REST API with Flask which add a photo to a database. The database is abstracted in PhotoModel Class. The API receives a JSON formated HTTP POST which contain the picture in a bin string an the name, all the other parameters are optional.</p>
  
  <p>How to construct "photo" object if some param aren't present in the JSON posted?
  On the database Model (PhotoModel) I have specify only two compulsory items, so the logic to only take into account params present in the JSON should be in the function bellow.</p>
  
  <pre><code>def add_photo():
  """Add photo to database"""
  if request.method == 'POST' and request.headers['Content-Type'] == 'application/json':
      photo = PhotoModel(
          name = request.json['name'],
          device_version = request.json['device_version'],
          date = request.json['date'],
          picture = request.json['picture'],
          comment = request.json['comment']
      )
      try:
          photo.put()
          return "200"
      except CapabilityDisabledError:
          return "500 DB read-only"
  else:
      return "415 Unsupported Media Type"
  </code></pre>
  
  <p>I can't figure out how to do it, any pointer would help</p>