Use django signals infrastructure. Handle post_save and post_delete
signal and add or delete profile. Example of creation:

from django.contrib.auth.models import User
from django.db.models import signals
from django.dispatch import dispatcher

def create_profile_for_user(sender, instance, signal, *args,
**kwargs):
    from myapp.models import Profile
    try:
        Profile.objects.get( user = instance )
    except ( Profile.DoesNotExist, AssertionError ):
        profile = Profile( user = instance )
        profile.save()

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

On 8 дек, 15:41, Julien <[EMAIL PROTECTED]> wrote:
> Thanks for the link Thomas. In fact I had already stumbled on django-
> profiles before. But I don't think this quite solve my problem.
>
> I'd like the profile to be automatically created when a new user is
> created, even when creating a user through the admin interface or
> through the shell for example.
>
> If the User class was a custom class of mine, I'd simply override the
> save() and delete() methods. But since the User class is built in
> Django, I don't know how to do to.
>
> Any idea how to solve this?
>
> Cheers!
>
> Julien
>
> On Dec 8, 10:52 pm, Thomas <[EMAIL PROTECTED]> wrote:
>
> > Julien,
>
> > have a look here:
>
> >http://www.b-list.org/weblog/2007/nov/24/profiles/
>
> > Thomas
>
> > On Dec 8, 12:20 pm, Julien <[EMAIL PROTECTED]> wrote:
>
> > > Hi all,
>
> > > I feel like my question must have been asked before, but I couldn't
> > > find any help on this group or through regular googling.
>
> > > All I'm trying to do is that whenever a new user is created (either
> > > through the admin interface, or with django-registration), an instance
> > > of the associated profile class (AUTH_PROFILE_MODULE) is created too.
>
> > > I guess I'd need to put a hook on the User.save() and delete()
> > > methods, am I right? How could I do that?
>
> > > Thanks a lot!
>
> > > Julien
--~--~---------~--~----~------------~-------~--~----~
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