0
I’m developing a CRUD system with class-based views. I have an app that List, Create and Delete views are working perfectly, but Update is having a problem. From Listview, I try to Updateview one of the objects, but the object data is not passed to Updateview, generating the error:
NoReverseMatch at /workOrder/8/
Reverse for 'WorkOrderUpdate' with arguments '('',)' not found. 1 pattern(s) tried: ['workOrder/(?P<pk>[0-9]+)/$']
workOrderList.html - Here the objects are shown correctly.
{% for workOrder in object_list %}
<tr>
<td>{{ workOrder.id }}</td>
<td>
<a href="{% url 'WorkOrderUpdate' workOrder.id %}">
<button type="button" class="btn btn-outline-info">Editar</button>
</a>
</td>
~ Botão de delete omitido ~
</tr>
{% endfor %}
urls.py - My four urls, all working except Update.
path('workOrder/add/', WorkOrderCreate.as_view(), name='WorkOrderCreate'),
path('workOrders', WorkOrderList.as_view(), name='WorkOrderList'),
path('workOrder/<int:pk>/', WorkOrderUpdate.as_view(), name='WorkOrderUpdate'),
path('workOrder/<int:pk>', WorkOrderDelete.as_view(), name='WorkOrderDelete'),
workOrderUpdate.html - Here my form that should receive the id passed by Listview.
<form action="{% url 'WorkOrderUpdate' workOrder.id %}" method='post'>
{% csrf_token %}
If I change to {% url 'WorkOrderUpdate' 8 %}
, the form is displayed perfectly (8 is one of the id present in my table).
views.py - Exactly like the views of other apps that are working (structurally speaking).
class WorkOrderUpdate(UpdateView):
model = WorkOrder
form_class = WorkOrderForm
template_name = 'workOrders/workOrderUpdate.html'
success_url = '/workOrders'
Forms.py - Exactly like the other apps that are working (structurally speaking).
class WorkOrderForm(forms.ModelForm):
class Meta:
model = WorkOrder
fields = ['customer', 'status']
customer = forms.ModelChoiceField(empty_label="Selecione", queryset=Customer.objects.all())
createdAt = forms.DateField(label="Criado em", input_formats=settings.DATE_INPUT_FORMATS)
status = forms.CharField(label="Status")
I have two other apps extremely similar to this, and they have all the views working correctly. Would anyone have any idea why my id is not passed to Updateview?
Hello, Denis. The problem is that probably the
workOrder.id
is returning None. Could you please share your view? @Denis Callau– Eliakin Costa
Added views.py and Forms.py
– Denis Callau