When the user selects the translator name, I want to access the selected translator in Django by the id and store the information in an appointment table in the database, but there is an error when he tries to mach the id the error is: Field 'id' expected a number but got ''.
view.py: where I took the user's chosen language and did a filler for the manager.
def customerHomePage(request):
if request.method == 'POST':
search_id = request.POST.get('textfield', None)
try:
pro = Manager.objects.filter(Second_Language = search_id)
x={'pro': pro}
return render(request,'representTranslator.html', x)#for show the customer Home page
except pro.DoesNotExist:
return HttpResponse("no such user")
else:
return render(request, 'customerHome.html')
HtML code: I displayed only the manager with the same chosen language to prompt the user to send a new message.
<section style="margin-top: 10%;">
<form method="POST" action="/waite" >
{% csrf_token %}
<select id="translator" name="translator">
{% for i in pro %}
<option value="{{ i.id }}"> {{ i.name }}</option>
{% endfor %}
</select>
<button type="submit">Send request</button>
</form>
</section>
in django view.py:
def waitePage(request):
if request.method == 'POST':
id = request.POST.get("translator")
translator = Manager.objects.get(user_id=id)
translatorName= translator.name #get the name of the translator
translatorID= translator.id #get the id of the translator
current_user = request.user #to get the user
current_userId = current_user.id #for storing user id
customer = Customer.objects.get(id=current_userId) #to get the info of translator
customerID=customer.id
customerName=customer.name
appointment = Appointment.objects.create(
customerName=customerName,
customerID=customerID, translatorID=translatorID, accepted=False,)
appointment.save()
return render(request,'waitePage.html')
The error comes from:
translator = Manager.objects.get(user_id=id)
Do you guys have any idea how I can solve it?
Do you guys have any idea how I can solve it?
int()
pro
is created and passed into the template.