@classmethod
def get_or_create(cls, defaults={}, **kwargs):
    """
        A port of functionality from the Django ORM. Defaults can be passed in
        if creating a new document is necessary. Keyword args are used to
        lookup the document. Returns a tuple of (object, created), where object
        is the retrieved or created object and created is a boolean specifying
        whether a new object was created.
        """
    result = cls.c.find_one(kwargs)
    if not result:
        created = True
        result = kwargs
        result.update(defaults)
        cls.update(result, result, upsert=True)
        result = cls.c.find_one(kwargs)
        instance = cls(**result)
    else:
        created = False
        instance = cls(**result)
    return instance, created
