Determine if an entity is created 'today'
<p>I am creating an app which, on any given day, only one entity can be created per day. Here is the model:</p>

<pre><code>class MyModel(ndb.Model):
    created = ndb.DateTimeProperty(auto_now_add=True)
</code></pre>

<p>Since only one entity is allowed to be created per day, we will need to compare the MyModel.created property to today's date:</p>

<pre><code>import datetime

class CreateEntity(webapp2.RequestHandler):
    def get(self):
        today = datetime.datetime.today()
        my_model = MyModel.query(MyModel.created == today).get()

        if my_model:
          # print("Today's entity already exists")
        else:
          # create today's new entity
</code></pre>

<p>The problem is that I cannot compare the two dates like this. How can I check if an entity was already created 'today'?</p>

<p>You are comparing a <code>DateTime</code> object with a <code>Date</code> object.</p>

<p>Instead of </p>

<pre><code>my_model = MyModel.query(MyModel.created == today).get()
</code></pre>

<p>use</p>

<pre><code>my_model = MyModel.query(MyModel.created.date() == today).get()
</code></pre>

python google-app-engine datetime google-cloud-datastore app-engine-ndb