Re: return pk id on Form
Thank you for the point in the right direction. In the end i now have:
@models.permalink
def get_absolute_url(self):
return ('c_viewcontact', [str(self.id)])
class ContactForm(ModelForm):
class Meta:
model = Contacts
fields = ('contact_type', 'firstname', 'surname', 'notes')
def addcontact(request, template_name='addcontact.html'):
if request.POST:
form = ContactForm(request.POST)
saved_form = form.save()
contact_id = saved_form
# If the save was successful, redirect to another page
redirect_url = get_absolute_url(contact_id)
return HttpResponseRedirect(redirect_url)
else:
form = ContactForm()
return render_to_response(template_name, {
'form': form, }, context_instance=RequestContext(request))
c_viewcontact being the name of the view.
Again, thank you for your help, it's much appreciated.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home