Good afternoon I'm doing an application in Django 1.10 and I need that when creating a record this sends me to another view with another template the Id of this record that I just created.
views.py
def datosBasicos(request): #En esta vista creo el nuevo registro
if request.method == 'POST':
beneficiario = Beneficiario()
beneficiario.numeroDocumento = request.POST['numeroDocumento']
beneficiario.nombreUno = request.POST['nombreUno']
beneficiario.save()
ben = Beneficiario.objects.get(id=beneficiario.id)
messages.success(request, validator.getMessage())
return HttpResponseRedirect('/beneficiario/beneficiario_create/%d/'%ben.id)
return render(request,'datosBasicos.html', informacion)
def beneficiario_create(request, id): #Necesito que me llegue a esta vista el id del registro creado
beneficiario = Beneficiario.objects.get(id = id)
return render(request,'beneficiario_create.html')
urls.py
urlpatterns = [
url(r'^$', beneficiario, name='beneficiario'),
url(r'^beneficiario_create/(?P<id>\d+)/$', beneficiario_create, name='beneficiario_create'),
]