Skip to content
The Chat Archive
gpt-3.5-turbo-0613· OpenAI WildChat-4.8M (AI2)

in this code def getuserdata(request): userprofile =…

  1. User

    in this code def get_user_data(request): user_profile = User_Profile.objects.filter(user=request.user) user_tender_permission = User_TenderPermission.objects.get(user=request.user) user_contract_permission = User_ContractPermission.objects.filter(user__in=user_profile) user_project_permission = User_ProjectPermission.objects.get(user=request.user) employee_profile = Employee_Profile.objects.get(user=request.user) user_OrgstructurePermission = User_OrgstructurePermission.objects.get(user=request.user) notification_to = Actions.objects.filter(Q(to_id__in=user_profile) & ~Q(is_read_cc__in=user_profile)) notification_cc = Actions.objects.filter(Q(cc__in=user_profile) & ~Q(is_read_cc__in=user_profile)) notification_count = notification_to.count() + notification_cc.count() circular_report = Circular.objects.filter(~Q(is_read_circular__in=user_profile) & ~Q(circular_no=None)) circular_notification_count = circular_report.count()

    return {
        'user_tender_permission': user_tender_permission,
        'user_contract_permission': user_contract_permission,
        'user_project_permission': user_project_permission,
        'user_profile': user_profile,
        'user_OrgstructurePermission': user_OrgstructurePermission,
        'employee_profile': employee_profile,
        'circular_notification_count':circular_notification_count,
        'notification_count':notification_count,
        'notification_to':notification_to,
        'notification_cc':notification_cc,
    
    }    
    

    @login_required(login_url='login') @c_1_contract_project_index def contract_project_index(request): data = get_user_data(request)

    all = Contract_Detail.objects.all().filter(project = data['user_profile'].project_name).count()
    
    # حساب تحديث العقد
    new = Contract_Detail.objects.all().filter(sgnllast_status_action='مدير المشروع', project = data['user_profile'].project_name)
    project_manager_count = new.count()
    
    # حساب الاصدار الجديد
    new = Contract_Detail.objects.all().filter(sgnllast_status_action__in =['اصدار جديد', 'تحديث طلب اصدار'])
    sector_manager_count = new.filter(project = data['user_profile'].project_name).count()
    
    # حساب مراجعة البيانات
    check_data = Contract_Detail.objects.all().filter(sgnllast_status_action='مراجعة البيانات')
    check_data_count = check_data.filter(project = data['user_profile'].project_name).count()
    
    # حساب تقدير التكاليف
    cost_estimation = Contract_Detail.objects.all().filter(sgnllast_status_action='تقدير التكاليف')
    cost_estimation_count = cost_estimation.filter(project = data['user_profile'].project_name).count()
    
    # حساب مراجعة المالية
    financial = Contract_Detail.objects.all().filter(sgnllast_status_action='مراجعة المالية')
    financial_count = financial.filter(project = data['user_profile'].project_name).count()
    
    # حساب ناسخ العقود
    copy_contract = Contract_Detail.objects.all().filter(sgnllast_status_action='ناسخ العقد')
    copy_contract_count = copy_contract.filter(project = data['user_profile'].project_name).count()
    
    # حساب مراجعة العقود
    check_contract = Contract_Detail.objects.all().filter(sgnllast_status_action='مراجعة العقد')
    check_contract_count = check_contract.filter(project = data['user_profile'].project_name).count()
    
    # حساب اعتماد tcta
    tcta = Contract_Detail.objects.all().filter(sgnllast_status_action='اعتماد الاجراءات')
    tcta_count = tcta.filter(project = data['user_profile'].project_name).count()
    
    # حساب اعتماد evp
    evp = Contract_Detail.objects.all().filter(sgnllast_status_action='نائب الرئيس التنفيذي')
    evp_count = evp.filter(project = data['user_profile'].project_name).count()
    
    # حساب اعتماد ceo
    ceo = Contract_Detail.objects.all().filter(sgnllast_status_action='الرئيس التنفيذي')
    ceo_count = ceo.filter(project = data['user_profile'].project_name).count()
    
    # حساب اعتماد asgnmnt
    asgnmnt = Contract_Detail.objects.all().filter(sgnllast_status_action='توقيعات')
    asgnmnt_count = asgnmnt.filter(project = data['user_profile'].project_name).count()
    
    # حساب الرفض
    refuse = Contract_Detail.objects.all().filter(sgnllast_status_action='رفض')
    refuse_count = refuse.filter(project = data['user_profile'].project_name).count()
    
    # حساب المكتمل
    complete = Contract_Detail.objects.all().filter(sgnllast_status_action='مكتمل')
    complete_count = complete.filter(project = data['user_profile'].project_name).count()
    try:
        complete_percentage = round((complete_count/all)*100)
    except ZeroDivisionError:
        complete_percentage = 0
    
    # حساب الجاري
    inprogress = Contract_Detail.objects.all().filter(~Q(sgnllast_status_action='مكتمل'), ~Q(sgnllast_status_action='رفض'))
    inprogress_count = inprogress.filter(project = data['user_profile'].project_name).count()
    context = {
        **data,
        'project_manager_count':project_manager_count,
        'sector_manager_count':sector_manager_count,
        'check_data_count':check_data_count,
        'cost_estimation_count':cost_estimation_count,
        'financial_count':financial_count,
        'copy_contract_count':copy_contract_count,
        'check_contract_count':check_contract_count,
        'tcta_count':tcta_count,
        'evp_count':evp_count,
        'ceo_count':ceo_count,
        'asgn2_count':asgnmnt_count,
        'refuse_count':refuse_count,
        'complete_count':complete_count,
        'inprogress_count':inprogress_count,
        'all':all,
        'complete_percentage':complete_percentage,
    }
    if request.user.is_staff:
        return render(request, 'contract/contract_main_index.html', context)
    else:
        return redirect('no_permission')
    

    i get this error 'QuerySet' object has no attribute 'project_name'

  2. Assistant

    The error message suggests that there is no attribute called 'project_name' in the 'QuerySet' object. From the code snippet you provided, it seems that the issue lies in this line:

    all = Contract_Detail.objects.all().filter(project = data['user_profile'].project_name).count()
    

    In this line, you are trying to access the 'project_name' attribute of 'user_profile' in the 'data' dictionary. However, 'user_profile' is a QuerySet object, which does not have a 'project_name' attribute.

    To resolve this issue, you need to make sure that you are passing the correct object to the 'get_user_data' function and that the 'user_profile' object indeed has a 'project_name' attribute. Double-check the logic in the 'get_user_data' function and ensure that you are storing the correct objects in the 'user_profile' attribute.

    You can also add some print statements or use a debugger to inspect the values of the objects at different points in the code to identify the exact cause of the issue.