How to return Object ID(primary key) on new record submit?

35 views
Skip to first unread message

Keith Pettit

unread,
Jul 9, 2009, 2:38:09 PM7/9/09
to django...@googlegroups.com
I'm using inlineformset_factory to create a database entry with child objects.  All works well for submiting a recording then returning to a record list.  But I need a way to submit the new record then continue editing the same document or reference it after submit.

I though there was something similar to doing a  "pk = obj.save()" but I can't seem to find the right way to do it.

Right now this is how I save my form/formset if you see any way I could approach this to get the database object id let me know.

# Parent Object (Ticket)
obj = form.save(commit=False)
obj.owner = request.user.get_profile()
obj.save()

# Child Items (Load)
formset = inlineformset_factory(Ticket, Load, fk_name="ticket", form=LoadForm)(request.POST, request.FILES, instance=obj)
if formset.is_valid():
   formset.save()



Thanks,

Keith Pettit

Javier Guerra

unread,
Jul 9, 2009, 4:11:17 PM7/9/09
to django...@googlegroups.com
On Thu, Jul 9, 2009 at 1:38 PM, Keith Pettit<ke...@setuplinux.com> wrote:
> I though there was something similar to doing a  "pk = obj.save()" but I
> can't seem to find the right way to do it.

after doing the "obj.save()", the obj will have an "id" attribute.

--
Javier

Reply all
Reply to author
Forward
0 new messages