Hi Milan,

On Jan 3, 2:37 pm, Milan Andric <[EMAIL PROTECTED]> wrote:
> Is it possible to set the destination of a redirect after a create in
> the admin?

Not without hacking into the Django admin code.

>
> My scenario is such that when users are created it's also necessary to
> create a profile object.  I'm trying to figure out a quick (possibly
> hack) that would make creating a user and profile easier.  (I know,
> it's just one more step, but it's a hassle.) One possibility is to
> just redirect people to the create profile page after a user is
> created.
>
> I thought about subclassing or patching the the User model's save()
> method to also create a profile on create.  But I'd like to avoid
> adding my own patches into django if possible.

If it's sufficient to create a profile without user intervention, you
can hook onto Django's "post_save" signal. In other words, Django can
be asked to call your custom Python function whenever a User.save() is
completed. The code goes something like this:

from django.contrib.auth import models

def user_created(sender, instance):
        # create profile for user instance here

dispatcher.connect(user_created, sender=models.User,
signal=signals.post_save)

Basically, you add this code to one of your applications' __init__.py
(or project's __init__.py) or anywhere else where it's guaranteed to
load when the application is started.

See more about signals here: http://code.djangoproject.com/wiki/Signals

If you need the user profile to also be filled up with user entered
data, you will need to create your own user creation view that
redirects to a profile creation view, etc.

-Rajesh D
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to