def get_by_id(cls, record_id, execute=True):
"""Return a single instance of the model queried by ID.
Args:
record_id (int): Integer representation of the ID to query on.
Keyword Args:
execute (bool, optional):
Should this method execute the query or return a query object
for further manipulation?
Returns:
cls | :py:class:`peewee.SelectQuery`:
If ``execute`` is ``True``, the query is executed, otherwise
a query is returned.
Raises:
:py:class:`peewee.DoesNotExist`:
Raised if a record with that ID doesn't exist.
"""
query = cls.base_query().where(cls.id == record_id)
if execute:
return query.get()
return query
评论列表
文章目录