Userprofile, signal and admin inline edit.

37 views
Skip to first unread message

Jani Tiainen

unread,
May 26, 2011, 5:23:35 AM5/26/11
to django...@googlegroups.com
If I extend auth.User with custom profile and add automatic profile
creation signal it works as expected.

But if I try to add admin inline editor for profile when saving I get
exception about integration violation.

It happens because admin tries to create second profile for user when
saving.

I can of course remove signal but that wouldn't create profile if I
insert user manually.

So how to make things work with both, admin inline profile editing and a
signal?

--

Jani Tiainen


Malcolm Box

unread,
May 26, 2011, 8:39:59 AM5/26/11
to django...@googlegroups.com
On 26 May 2011 10:23, Jani Tiainen <red...@gmail.com> wrote:
If I extend auth.User with custom profile and add automatic profile
creation signal it works as expected.

But if I try to add admin inline editor for profile when saving I get
exception about integration violation.

It happens because admin tries to create second profile for user when
saving.


Have your signal handler check whether this is a creation of a user or an edit. Only create the profile in the first case.

You may also need to check whether the profile already exists before trying to create - get_or_create() is your friend here.
 
Malcolm

Jon Biddle

unread,
Jun 14, 2011, 11:04:09 AM6/14/11
to Django users
The issue seems to come from the fact that the order of operations
when you create the user looks like this:

1) Django admin saves the new User
2) post_save on User is triggered, and User's profile is created
3) Django admin saves the UserProfile... but it already exists, and an
integrity error is raised


I'm currently looking into a solution to this as well, and will let
you know what I find.

On May 26, 8:39 am, Malcolm Box <malcolm....@gmail.com> wrote:

Daniel Gerzo

unread,
Nov 29, 2012, 4:44:42 AM11/29/12
to django...@googlegroups.com
Hello Jon,

have you ever found a solution for this? Thanks.
Reply all
Reply to author
Forward
0 new messages