On 27 nov, 17:11, Paddy Joy <[EMAIL PROTECTED]> wrote:
> Thanks for the tips, signals would work except I need access to the
> raw password when users are created.
>
> On further inspection it seems I would need to override the
> UserManager,

On even further inspection, you may in fact want to override
User.set_password !-)

> I know I can extend it with more methods but I don't
> think I can override it.

As Alex said, you can always - I mean, as a _last_ resort -
monkeypatch it:

# mymodel.py
from auth.models import UserManager
_create_user = UserManager.create_user
def my_create_user(self, username, email, password=None):
    # do whatever here
    # and eventually remember to call the original method
    return _create_user(self, username, email, password)

UserManager.create_user = my_create_user

# et voilĂ .



> Paddy
>
> On Nov 27, 12:39 am, sergioh <[EMAIL PROTECTED]> wrote:
>
> > Signals are the better way to achieve. You usually override the save
> > method when you need to define something related with the model
> > itself, but in many cases signals are the better way to notify some
> > function to do something if a model change (after save)
>
> > def your_function(sender, instance, created=False, **kwargs):
> >       # your tasks
>
> > models.signals.post_save.connect(your_function, sender=User)  #this
> > relate your User model with the signal
>
> > regards,
>
> > Sergio Hinojosa
>
> > On Nov 26, 7:01 am, "Alex Koshelev" <[EMAIL PROTECTED]> wrote:
>
> > > Of course you can monkey-patch the User model but the better way is to use
> > > signals pre_ or post_save
>
> > > On Wed, Nov 26, 2008 at 13:54, Paddy Joy <[EMAIL PROTECTED]> wrote:
>
> > > > I would like to override the save() method on the contrib.auth User
> > > > model so that I can run a routine when a user is created/modified.
>
> > > > Is this possible or do I need to use a signal? I have tried overriding
> > > > the User model like this but it never seems to call my code:
>
> > > > from django.contrib.auth.models import User
>
> > > > # Override User model
> > > > class User(models.Model):
>
> > > >        def save(self):
>
> > > >                # Do something here
> > > >                myroutine()
> > > >                super(User, self).save()
>
> > > > Can anyone help?
>
> > > > Paddy
--~--~---------~--~----~------------~-------~--~----~
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