title: How to avoid duplicates in GAE datastore?
body: <p>Let's say here is the database structure:</p>
  
  <pre><code>class News(db.Model):
      title = db.StringProperty()
  
  class NewsRating(db.Model):
      user = db.IntegerProperty()
      rating = db.IntegerProperty()
      news = db.ReferenceProperty(News)
  </code></pre>
  
  <p>Each user can leave only one rating for each News. The following code doesn't care about duplicates:</p>
  
  <pre><code>rating = NewsRating()
  rating.user = 123456
  rating.rating = 1
  rating.news = News.get_by_key_name('news-unique-key')
  rating.put()
  </code></pre>
  
  <p>How should I modify that that it will allow to have only one record for each <code>rating.user</code> and <code>rating.news</code> combination? If such rating already exists, then it should be updated with new value.</p>