HI Here is my code for comparing two mobiles technical specifications
def getFormValues(request):
if ('mobile_a' in request.GET and request.GET['mobile_a']) and ('mobile_b' in request.GET and request.GET['mobile_b']):
mobile_a = request.GET['mobile_a']
mobile_b =request.GET['mobile_b']
# calling the mark calculation function
return calculateMark(mobile_a, mobile_b)
else:
message ='You submitted an empty form.'
return HttpResponse(message)
def calculateMark(mobile_a, mobile_b):
#variables
mobile_a = mobile_a
mobile_b = mobile_b
tech_mark_a= 0
tech_mark_b = 0
results_a = []
results_b = []
record_a = TechSpecificationAdd.objects.filter(mobile_name=mobile_a).values()
record_b = TechSpecificationAdd.objects.filter(mobile_name=mobile_a).values()
results_a += record_a
results_b += record_b
#dimension
if int(record_a["dimension"]) > int(record_b["dimension"]):
tech_mark_a = 1
else:
tech_mark_b = 1
#body-material
#weight
if record_a["weight"] > record_b["weight"]:
tech_mark_b += 1
else:
tech_mark_a += 1
#camera
if record_a["camera"] > record_b["camera"]:
tech_mark_a += 1
else:
tech_mark_b += 1
#flash
if (record_a["flash"]):
tech_mark_a += 1
if (record_b["flash"]):
tech_mark_b += 1
#video
if record_a["video"] > record_b["video"]:
tech_mark_a += 1
else:
tech_mark_b += 1
#fps
if record_a["fps"] > record_b["fps"]:
tech_mark_a += 1
else:
tech_mark_b += 1
#front-camera
if record_a["front_camera"] > record_b["front_camera"]:
tech_mark_a += 1
else:
tech_mark_b += 1
return render_to_response('degrees_result.html', {'data_a': results_a, 'data_b': results_b})
In this situation django debug is showing the error "TypeError at /calculate_mark/ No exception supplied". If you ask for Traceback infos then I can provide.
So What is the problem? I could't figure out.
QuerySet.values returns ValuesQuerySet object (which is similar to list of dictionaries)
record_a = TechSpecificationAdd.objects.filter(mobile_name=mobile_a).values()
But the code is using it as if it is a dictionary:
int(record_a["dimension"])
Convert such usage as follow:
int(record_a[0]["dimension"])
or convert record_a as dictionary:
record_a = record_a[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With