Issue
I'm having a hard time displaying some datas from two or three tables. So this is my code for showing all the data only from Device table.
def device(request):
if request.method == 'GET':
queryset = Device.objects.all()
if queryset:
data = {"queryset": queryset}
return render(request, 'device/device.html', data)
else:
return render(request, 'device/device.html')
And I want to add some data from other table, how do I insert it here?
Solution
Just make the queries and put the results in the render context, and refer to those in your template.
return render(request, 'device/device.html', {
"devices": Device.objects.all(),
"thingabobs": Thingabob.objects.all(),
"chili_pickles": Pickle.objects.filter(flavor="chili"),
"plain_pickles": Pickle.objects.filter(flavor="plain"),
})
Answered By - AKX
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.