Google App Engine - adding an entry only if it does not already exist

In the Google App Engine, consider the following data warehouse model:

class Update(db.Model):
    content = db.TextProperty()
    date = db.DateTimeProperty()
    source = db.StringProperty()

To add a new entry, I am doing something like:

db.put(Update(content=..., date=..., source=...))

How to add a record to the data warehouse only if it does not exist yet? What is the most efficient way to do this?

+3
source share
1 answer

db.Model.get_or_insert(key_name) allows you to pass a key name for an object to get or insert (think of it as a primary key)

Additional information on key_name

+5
source

Source: https://habr.com/ru/post/1778433/


All Articles