Skip to content

Commit 2e33b6c

Browse files
committed
获取数据时,增加城市作为过滤条件
1 parent 868c708 commit 2e33b6c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

coronavirus/crud.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ def create_city(db: Session, city: schemas.CreateCity):
2727
return db_city
2828

2929

30-
def get_data(db: Session, skip: int = 0, limit: int = 10):
30+
def get_data(db: Session, city: str = None, skip: int = 0, limit: int = 10):
31+
if city:
32+
return db.query(models.Data).filter(models.Data.city.has(province=city)) # 外键关联查询,这里不是像Django ORM那样Data.city.province
3133
return db.query(models.Data).offset(skip).limit(limit).all()
3234

3335

0 commit comments

Comments
 (0)