-
Notifications
You must be signed in to change notification settings - Fork 0
6. Pagination
cjlotto edited this page Aug 12, 2023
·
1 revision
def get_question_list(db: Session, skip: int = 0, limit: int = 10):
_question_list = db.query(Question).order_by(Question.create_date.desc())
total = _question_list.count()
question_list = _question_list.offset(skip).limit(limit).all()
return total, question_list
- skip : 조회 데이터의 시작 위치
- limit : 시작 위치(skip)부터 가져올 데이터양
class QuestionList(BaseModel):
total: int = 0
question_list: list[Question] = []
- question_schema.py
@router.get("/list", response_model=list[question_schema.QuestionList])
def question_list(db: Session = Depends(get_db), page: int = 0, size: int = 10):
total, _question_list = question_crud.get_question_list(
db, skip=page * size, limit=size
)
return {"total": total, "question_list": _question_list}
- question_router.py