if语句的值不返回到父函数的上下文视图

问题描述 投票:0回答:1

这是我要在函数上下文中使用obj3的视图

def inec_news_view(request):

    title = 'LGA Results'
    data1 = Lga.objects.all()

    if request.method == 'POST':
        selected_item = request.POST.get('item_id')
        obj3 = Pu_results.objects.filter(polling_unit_uniqueid__in=Subquery(Unit.objects.values('uniqueid').filter(lga_id=obj1)))
    context = {'title': title, 'data1': data1, 'resobj': obj3}
    return render(request, "inecnews.html", context)
python django python-3.x view
1个回答
0
投票
    This is how I answered it
def inec_news_view(request): # *args, **kwargs
        title = 'LGA Results'
        data1 = Lga.objects.all()
        context = {'title': title, 'data1': data1}

        if request.method == 'POST':
            selected_item = request.POST.get('item_id')
            obj = Lga.objects.get(lga_id=selected_item)
            obj1 = obj.lga_id
            obj3 = Pu_results.objects.filter(polling_unit_uniqueid__in=Subquery(Unit.objects.values('uniqueid').filter(lga_id=obj1)))


            context = {'title': title, 'data1': data1, 'resobj': obj3}
        return render(request, "inecnews.ht

ml“,上下文)

© www.soinside.com 2019 - 2024. All rights reserved.