diff --git a/app/api/endpoints/address.py b/app/api/endpoints/address.py index f298e7a..59e2e3f 100644 --- a/app/api/endpoints/address.py +++ b/app/api/endpoints/address.py @@ -106,17 +106,19 @@ async def update_address( for key, value in update_data.items(): setattr(db_address, key, value) - # 查询社区名字和楼栋名字 - community = db.query(CommunityDB).filter( - CommunityDB.id == address.community_id - ).first() + # 更新社区名字和楼栋名字 + if address.community_id: + community = db.query(CommunityDB).filter( + CommunityDB.id == address.community_id + ).first() + db_address.community_name = community.name - community_building = db.query(CommunityBuildingDB).filter( - CommunityBuildingDB.id == address.community_building_id - ).first() + if address.community_building_id: + community_building = db.query(CommunityBuildingDB).filter( + CommunityBuildingDB.id == address.community_building_id + ).first() + db_address.community_building_name = community_building.building_name - db_address.community_name = community.name - db_address.community_building_name = community_building.building_name db.commit() db.refresh(db_address)