from google.appengine.ext import ndb


class BaseModel(ndb.Model):
    date_created = ndb.DateTimeProperty(auto_now_add=True, required=True)
    date_modified = ndb.DateTimeProperty(auto_now=True, required=True)

from google.appengine.ext import ndb


class BaseModel(ndb.Model):
    date_created = ndb.DateTimeProperty(auto_now_add=True, required=True)
    date_modified = ndb.DateTimeProperty(auto_now=True, required=True)

    @classmethod
    def from_urlsafe(cls, urlsafe):
        key = ndb.Key(urlsafe=urlsafe)
        obj = key.get()
        if obj and isinstance(obj, cls):
            return obj

Add a utility method to get instances from urlsafe key.
Add a utility method to get instances from urlsafe key.

  from google.appengine.ext import ndb
  
  
  class BaseModel(ndb.Model):
      date_created = ndb.DateTimeProperty(auto_now_add=True, required=True)
      date_modified = ndb.DateTimeProperty(auto_now=True, required=True)
  
+     @classmethod
+     def from_urlsafe(cls, urlsafe):
+         key = ndb.Key(urlsafe=urlsafe)
+         obj = key.get()
+         if obj and isinstance(obj, cls):
+             return obj
+ 
Add a utility method to get instances from urlsafe key.
## Code Before:
from google.appengine.ext import ndb


class BaseModel(ndb.Model):
    date_created = ndb.DateTimeProperty(auto_now_add=True, required=True)
    date_modified = ndb.DateTimeProperty(auto_now=True, required=True)

## Instruction:
Add a utility method to get instances from urlsafe key.
## Code After:
from google.appengine.ext import ndb


class BaseModel(ndb.Model):
    date_created = ndb.DateTimeProperty(auto_now_add=True, required=True)
    date_modified = ndb.DateTimeProperty(auto_now=True, required=True)

    @classmethod
    def from_urlsafe(cls, urlsafe):
        key = ndb.Key(urlsafe=urlsafe)
        obj = key.get()
        if obj and isinstance(obj, cls):
            return obj
