[Answered ]-How can I get the id of the particular modelform?

2👍

 if request.method == 'POST':
            form = registrationform(request.POST)
            if form.is_valid():
                data =form.save()
                #...
                id = data.id
                #...
            return HttpResponseRedirect(reverse('reg.views.thanks', args=(id)))

0👍

user = form.save(commit=False)
user.first_name = u'First name'
user.last_name = u'Last name'
user.save()

For password use password1 field

👤ssbb

0👍

How about changing your registration function to this:

def registration(request):
    if request.method == 'POST':
        form = registrationform(request.POST)
        if form.is_valid():
            userdetails = form.save()
            user = userdetails.username
            val = registration.objects.get(username = user)
            return HttpResponseRedirect(reverse('reg.views.thanks', args=(val.id)))
    else:
        form = registrationform()
        return render_to_response('registration.html', {'form' : form}, context_instance=RequestContext(request))

I suggest you read this: https://docs.djangoproject.com/en/dev/topics/forms/modelforms/

0👍

Please could you paste your urls.py?

I recently had a problem almost exactly the same as this – it was just a typo there, I had the wrong value in in second field of the url function:

url(r'^people/thanks/(?P<person_id>\d+)$', 'people.views.thanks'),

Should have been:

url(r'^people/thanks/(?P<person_id>\d+)$', 'people.views.new'),

Leave a comment