model #34

Merged
Verox merged 2 commits from model into master 2024-02-14 21:54:04 +01:00
3 changed files with 5 additions and 4 deletions
Showing only changes of commit 4e93a2473c - Show all commits

View File

@ -58,12 +58,10 @@ def update_user(id: int, name: str, email: str, password: str = None):
def delete_user(id: int):
query = f"DELETE FROM habit_lists WHERE (SELECT list_id FROM habit_users WHERE user_id = {id}) = id;"
query2 = f"DELETE FROM users WHERE id = {id};"
query = f"DELETE FROM users WHERE id = {id};"
conn = con3()
cursor = conn.cursor()
cursor.execute(query)
cursor.execute(query2)
conn.commit()
conn.close()
return cursor.lastrowid

View File

@ -1,5 +1,5 @@
from dataclasses import dataclass
from datetime import date, datetime
from datetime import datetime
from models.Habit import Habit
from models.User import User

View File

@ -31,6 +31,9 @@ class User(UserMixin):
update_user(self.id, self.name, self.email, self.password if self.password else None)
def delete(self):
habitLists = self.get_habitLists()
for habitList in habitLists:
habitList.delete(self.id)
delete_user(self.id)
def get_habitLists(self) -> list: