def incident_detail(request, incident_id): incident = get_object_or_404(Incident, pk = incident_id ) sol = incident.solution_set.all() if request.method == 'POST': form = FormIncidentEdit(request.POST, instance=incident) if form.is_valid(): form.save() return render_to_response("view_detail.html", {'incident':incident, 'form':form, 'sol': sol },context_instance=RequestContext(request)) else: form = FormIncidentEdit(instance=incident) return render_to_response("detail.html", {'incident':incident, 'form':form },context_instance=RequestContext(request))
def new_incident(request): if request.method == 'POST': form=FormIncidentEdit(request.POST) form_client = FormClient(request.POST) if form_client.is_valid(): client = form_client.save() if form.is_valid(): new_incident = form.save(commit=False) new_incident.author = request.user new_incident.client = client new_incident.save() form.save_m2m() return HttpResponseRedirect(reverse('list_inc')) else: form = FormIncidentEdit(initial={'title':'название темы'}) form_client = FormClient() #form.author = request.user return render_to_response("new_inc.html", {'form':form, 'form_client':form_client }, context_instance=RequestContext(request))