def __init__(self, model_class): self.model_class = model_class self.key = model_class._key # We access directly _meta as .db is a property and should be # access from an instance, not a Class self._db = model_class._meta["db"] or modelplus.get_db() self._filters = {} self._exclusions = {} self._ordering = [] self._limit = None self._offset = None # Insure that we've done any necessary DB work to make this class happen self.db.construct(model_class._key)
def exists(cls, id): """Checks if the model with id exists.""" return bool((cls._meta['db'] or modelplus.get_db()).exists(cls._key[str(id)]))
def setUp(self): self.client = modelplus.get_db() self.client.flushdb()
def db(self): """Returns the Redis client used by the model.""" return modelplus.get_db() if not self._meta['db'] else self._meta['db']