I keep getting the error:
NoReverseMatch for 'grouplocation_add' with arguments '('',)' not found. 1 pattern(s) tried: [u'ipaswdb/grouplocations/add/(?P<pk>[0-9]+)/$']
After EDIT of adding context['group_id']=None on createview got this:
NoReverseMatch: Reverse for 'grouplocation_add' with arguments '(None,)' not found. 1 pattern(s) tried: [u'ipaswdb/grouplocations/add/(?P<pk>[0-9]+)/$']
The pattern:
url(r'^grouplocations/add/(?P<pk>[0-9]+)/$', GroupLocationCreateView.as_view(), name='grouplocation_add'),
Again if its an update where group_id exists, it works...if it is create new it is not but I thought my {% if ... %} and {% else %} would handle that scenario.
I am pretty sure it is my url 'ipaswdb:grouplocation_add group_id
when group Id doesn't exist (it does if this is being called when an update is happening, but creating a new group, no id yet. The button this is on is to do more things for a group that has already been created. My If else was an attempt to say 'until the form has been submitted thusly the model saved thusly doing an update view with the model.... ' don't enable the button that lets you muck with the other parts of the model until it has been saved once.
{% 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 %}
Given the error clearly my approach is different. I want to also save and return to the update view not the create view. So does that mean in my
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("")
Given once the page loads, that group_id exsists if it is loaded from the UpdateView then do I need the HttpResponseRedirect to go to the UpdateView somehow? How could I grab the model saved from the create view and pass it onto the updateview right in one step?
1) So I guess two things: Why is it giving that error when it is in an if else block.
2) once I fix that error how do I get the if else block to work by effectively turning around from the create view (the end that has the HttpResponseRedirect) and calling the UpdateView with the newly created model thusly having a group_id (that is passed into the contex in the UpdateView)
答案 0 :(得分:0)
在您的else语句中group_id为none的事实。 因此,您应将该字段指定为none。