I received an error message as follows:
NoReverseMatch for 'grouplocation_add' with arguments '('',)' not found. 1 pattern(s) tried: [u'ipaswdb/grouplocations/add/(?P<pk>[0-9]+)/$']
After adding context['group_id']=None to createview, I encountered this issue:
NoReverseMatch: Reverse for 'grouplocation_add' with arguments '(None,)' not found. 1 pattern(s) tried: [u'ipaswdb/grouplocations/add/(?P<pk>[0-9]+)/$']
The URL pattern in question:
url(r'^grouplocations/add/(?P<pk>[0-9]+)/$', GroupLocationCreateView.as_view(), name='grouplocation_add'),
Although the update works with an existing group_id, it fails when trying to create a new one. The {% if ... %} and {% else %} statements were supposed to handle this scenario.
I suspect that the issue lies in my
url 'ipaswdb:grouplocation_add group_id
when there is no group ID present for a new entry. The button functionality should be disabled until the form has been submitted and model saved - then enable it only for updating the model.
{% if group_id %}
<td><a href=""><button disabled type="button" id="group_add_location" class="btn btn-primary">Add A Group
Location</button></a> </td>
{% else %}
<td><a href="{% url 'ipaswdb:grouplocation_add' group_id %}"><button type="button" id="group_add_location" class="btn btn-primary">Add A Group
{% endif %}
The error suggests a different approach is needed. I also want to save and return to the update view instead of the create view. How can I achieve this within my code?
class GroupCreateView(CreateView):
..do tons of stuf
def get_context_data(self, **kwargs):
..do more stuf
context['group_id'] = None #added this
def post(self, request, *args, **kwargs):
if self.request.POST.has_key('submit'):
..DO LOTS OF STUFF..
return HttpResponseRedirect("")
Considering that the group_id exists once the page loads from the UpdateView, do I need to redirect to the UpdateView after creating? How can I pass the newly created model to the UpdateView in one step?
1) Why am I getting the error within the if-else block?
2) Once the error is fixed, how can I make the if-else block function correctly, transitioning from the create view (after the HttpResponseRedirect) to calling the UpdateView with the newly created model and assigned group_id?