Adds delete function at a class level.

This commit is contained in:
Simon Prickett 2022-02-14 20:44:49 +00:00
parent 2be01743a3
commit 885b24b35b
3 changed files with 38 additions and 0 deletions

View file

@ -1335,6 +1335,10 @@ class HashModel(RedisModel, abc.ABC):
result = cls.parse_obj(document)
return result
@classmethod
async def delete(cls, pk: Any) -> int:
return await cls.db().delete(cls.make_primary_key(pk))
@classmethod
@no_type_check
def _get_value(cls, *args, **kwargs) -> Any:
@ -1503,6 +1507,10 @@ class JsonModel(RedisModel, abc.ABC):
raise NotFoundError
return cls.parse_raw(document)
@classmethod
async def delete(cls, pk: Any) -> int:
return await cls.db().delete(cls.make_primary_key(pk))
@classmethod
def redisearch_schema(cls):
key_prefix = cls.make_key(cls._meta.primary_key_pattern.format(pk=""))