HabitTracker/models/HabitTracking.py
Yapollon 759c7d277f Model Overhaul
I'm done, this is the now complete code for the models and all.

To make it short:
- made some renaming that was necessary, HabitTrackings -> HabitTracking because every goddamn class is singular and not plural
- made the deletion process everywhere the same (Habit Deletion now handles the HabitTracking deletion inside the model and not through Sqlite.py)
- Some much needed comments
- Some adjustments to the HabitLists, nothing big, plus addition of update

- Also as a question, why does the HabitList have a redundant habits attribute, for now i marked this issue in the code to not forget it
2024-02-16 17:57:49 +01:00

27 lines
798 B
Python

from datetime import date, datetime
from dataclasses import dataclass
from db.SQLiteClient import create_habitTracking, get_habitTracking, delete_habitTracking
@dataclass
class HabitTracking:
id: int
habit_id: int
created_at: date
@staticmethod
def create(habit_id: int):
id = create_habitTracking(habit_id)
return HabitTracking(id, habit_id, datetime.now())
@staticmethod
def get(id: int):
habitTrackings = get_habitTracking(id)
return HabitTracking(habitTrackings[0], habitTrackings[1],
datetime.strptime(habitTrackings[2], "%Y-%m-%dT%H:%M:%S.%f")) \
if habitTrackings else None
# Deletes the HabitTracking
def delete(self):
delete_habitTracking(self.id)