Here, select machine name and operation number, after select and save, It is displaying none instead of data like machine name and operation number in the form of table. Please help me out to solve this. I am new in Django.
urls.py:
urlpatterns = [
path('upload/',views.upload,name='upload'),
path('save',views.save_machine,name='save_machine')
]
views.py:
def upload(request):
machines = Machine.objects.all()
return render(request,'usermaster/upload.html',{'machines':machines})
def save_machine(request):
if request.method == "POST":
machine_name = request.POST.get('machine_name', '')
operation_no = request.POST.get('operation_no')
choiced_machine = Machine.objects.get(machine_name=machine_name, operation_no=operation_no)
machines = Machine.objects.all()
return render(request,'usermaster/upload.html',{'machines':machines,'choiced_machine':choiced_machine})
models.py:
class Machine(models.Model):
machine_name = models.CharField(max_length=200)
operation_no = models.IntegerField(null=False)
def __str__(self):
return self.machine_name
upload.html:
<form action="{% url 'save_machine' %}" method="post">
{% csrf_token %}
<select>
<option>Select Machine Name</option>
{% for machine in machines %}
<option name="machine_name">{{ machine.machine_name }}</option>
{% endfor %}
</select>
<br>
<br>
<select>
<option>Select Operation Number</option>
{% for machine in machines %}
<option name="operation_no">{{ machine.operation_no }}</option>
{% endfor %}
</select>
<br>
<br>
<br>
<input type="submit" value="Save">
</form>
<tr>
<td>{{choiced_machine.machine_name}}</td>
<td>{{choiced_machine.operation_no}}</td>
</tr>