删除合约/品种时同步清空对应行情数据
This commit is contained in:
@@ -112,6 +112,7 @@ def toggle_contract(contract_id: int, db: Session = Depends(get_db)):
|
||||
def delete_contract(contract_id: int, db: Session = Depends(get_db)):
|
||||
c = db.query(Contract).filter(Contract.id == contract_id).first()
|
||||
if c:
|
||||
db.query(DailyBar).filter(DailyBar.contract == c.code).delete()
|
||||
db.delete(c)
|
||||
db.commit()
|
||||
return RedirectResponse("/admin/?tab=contract", status_code=303)
|
||||
@@ -121,6 +122,8 @@ def delete_contract(contract_id: int, db: Session = Depends(get_db)):
|
||||
def delete_product(product_id: int, db: Session = Depends(get_db)):
|
||||
p = db.query(Product).filter(Product.id == product_id).first()
|
||||
if p:
|
||||
for c in p.contracts:
|
||||
db.query(DailyBar).filter(DailyBar.contract == c.code).delete()
|
||||
db.delete(p)
|
||||
db.commit()
|
||||
return RedirectResponse("/admin/?tab=product", status_code=303)
|
||||
|
||||
Reference in New Issue
Block a user