Reputation: 367
I have the following code in views:
def submit_affective(request):
if request.method == 'POST':
choice=request.POST['aff_choices']
urlid=request.POST['url_list']
url = Url.objects.get(id=urlid)
aff_result=Affective.objects.create(
affective=choice, url=url
)
return redirect('detail_affective',id=url.id)
def detail_affective(request,id):
boring_count=Affective.objects.filter(affective='Boring',url.id=id).count()
confusing_count=Affective.objects.filter(affective='Confusing',url.id=id).count()
engaging_count=Affective.objects.filter(affective='Engaging',url.id=id).count()
context = {
'boring_count':boring_count,
'confusing_count':confusing_count,
'engaging_count':engaging_count,
}
return render(request,'feedback/detail_affective.html',context)
I want to show the number of "boring","confusing","engaging" in detail_affective
only for that URL for which choice has been submitted in submit_affective
. Please tell me the problem in my code. Am I passing the url id to detail_affective correctly? And is my way of filtering correct?
Upvotes: 0
Views: 22
Reputation: 47374
You cannot use url.id
expression as filter argument, just use url_id
instead:
boring_count=Affective.objects.filter(affective='Boring',url_id=id).count()
confusing_count=Affective.objects.filter(affective='Confusing',url_id=id).count()
engaging_count=Affective.objects.filter(affective='Engaging',url_id=id).count()
Also you need to add id
as url agrument argument to the urlpattern:
path('detail_affective/<int:id>',views.detail_affective,name='detail_affective')
Upvotes: 1