Add word list edit mode with bulk delete and fix word deletion

Show checkboxes and batch actions only after entering edit mode, and delete related quiz records before removing words to avoid foreign key failures.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-06-05 10:10:40 +08:00
parent ebd5440d45
commit 2fae90b597
3 changed files with 246 additions and 12 deletions
+5 -1
View File
@@ -4,7 +4,7 @@ from typing import Optional
from fastapi import HTTPException
from sqlalchemy.orm import Session
from models import Word, User
from models import QuizRecord, Word, User
def utc_now_iso() -> str:
@@ -68,6 +68,10 @@ class WordService:
def delete_word(self, db: Session, user: User, word_id: int) -> None:
word = self.get_word(db, user, word_id)
db.query(QuizRecord).filter(QuizRecord.word_id == word.id).delete(
synchronize_session=False
)
db.flush()
db.delete(word)
db.commit()