Как подключиться к models.py? Некоторые виды Django views.py не работают

я новичок в django/python. у меня есть проект на Django для расчета цены бумаги.

class Calculate(View):
def get(self, request):
    if not request.user.is_authenticated:
        return redirect('signIn')

    user = request.user
    projects = Project.objects.all()
    p_info_list = []
    u_info = UserInfo(user)
    user_in_projects = []
    k_info_list = []


    for p in projects:
        tasks = p.task_set.all()
        print(f"Project: {p.name}, Tasks: {tasks}")
        print(f"p object: {p}")
        for task in tasks:
            print(f"Task object: {task_object}")  # Check the value before object creation

        if p.owner == user or user.id in p.get_members():
            p_info = ProjectInfo(p)
            u_info.analyze_project(p)
            p_info_list.append(p_info)
            user_in_projects.append(UserInProject(user, p))
            print(f"P Info object: {p_info}")

        for task in p.task_set.all():
            print(f"Task object: {task}")  # Print the entire task object
            print(f"Task: {task.name}, tipe_kertas: {task.tipe_kertas}")

            k_info_obj = KalkulatorInfo(task)  # Or pass relevant data containing paper properties
            print(f"KalkulatorInfo object: {k_info_obj}")
            price = k_info_obj.calculate_price(task.tipe_kertas, task.gramatur_kertas, task.ukuran_kertas)
            k_info_obj.price = price  # Assuming KalkulatorInfo has a price attribute
            k_info_list.append(k_info_obj)

почему task_object не работает, когда я отлаживаюсь от print()

все for task in p.task_set.all() не работают.

здесь models.py:

class KalkulatorInfo:
def __init__(self, task_object):
    self.tipe_kertas = task_object.tipe_kertas  # Assuming task object has these attributes
    self.gramatur_kertas = task_object.gramatur_kertas
    self.ukuran_kertas = task_object.ukuran_kertas
    self.price = self.calculate_price()  # Calculate price upon initialization

def calculate_price(self):
    price_dict = {
        ("ap", "80", "a4"): 10000,
        ("bp", "100", "a4"): 12000,
        # ... other combinations and prices
    }
    print(f"this is price dict: {price_dict}")

Спасибо за помощь. Я благодарен за это

Вернуться на верх