Hi,
I have problem when getting the ID of the record just created.

class CreateFlow(CreateView):
model = Flow
fields = ['state']
template_name = 'create_flow.html'
def form_valid(self, form):
user = User.objects.get(pk=self.request.user.id)
flow = Flow.objects.get(pk=self.kwargs['pk'])
log = Log(user=user, flow=flow, state=1)
log.save()
return super(CreateFlow, self).form_valid(form)

... gives the error:
Request Method: POST
Request URL: http://127.0.0.1:8000/create/
Django Version: 1.7
Exception Type: KeyError
Exception Value: 
'pk'
Exception Location: C:\landy\cresta\flow\views.py in form_valid, line 64
Python Executable: C:\landy\Scripts\python.exe
Python Version: 3.4.0
Python Path: 
['C:\\landy\\cresta',
 'C:\\Windows\\system32\\python34.zip',
 'C:\\Python34\\DLLs',
 'C:\\Python34\\lib',
 'C:\\Python34',
 'C:\\landy',
 'C:\\landy\\lib\\site-packages']
Server time: Mon, 13 Oct 2014 13:40:49 +0100

What is the correct way to get the ID of the record just created?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8aaceba9-0203-489a-a57f-09fa26ce163c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to