Issue
I am showing "well" information linked to a specific project successfully based on well_id When I try to show drilling_tools in a similar fashion I get an error. Can anyone see what I am doing wrong in my views?
def well_show(request, well_id):
well = Well.objects.get(pk=well_id)
drilling_tools = DrillingTool.objects.get(pk=well_id)
return render(request, 'geodata/well_show.html', {'well': well, 'drilling_tools': drilling_tools})
Solution
Try this instead if they are related:
def well_show(request, well_id):
well = Well.objects.get(pk=well_id)
drilling_tools = DrillingTool.objects.filter(well__id=well_id)
return render(request, 'geodata/well_show.html', {'well': well, 'drilling_tools': drilling_tools})
Your code isn't working because the well.id
can differ from the drilling_tools.id
. They are in a separate table after all, and some funky (but easily preventable) race conditions can occur.
Answered By - nigel239
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.