Thanks however I'm guessing:
>
> admin.site.unregister(User)
> admin.site.register(User, NewModelForm)
>

will only work in the admin site? Not actually using the admin site at
the moment but would nice to have something that would work globally.


I nearly have the monkey patch working however I'm getting the
following error, any idea?

>>> from django.contrib.auth.models import UserManager
>>> a=UserManager()
>>> a.create_user(username='sdf', email='[EMAIL PROTECTED]', password='222')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/var/django/mysite/../mysite/hosting/models.py", line 166, in
my_create_user
    return _create_user(self, username, email, password)
  File "/usr/lib/python2.5/site-packages/django/contrib/auth/
models.py", line 100, in create_user
    user = self.model(None, username, '', '', email.strip().lower(),
'placeholder', False, True, False, now, now)
TypeError: 'NoneType' object is not callable
>>>


On Nov 28, 2:28 pm, sergioh <[EMAIL PROTECTED]> wrote:
> Maybe you could override the save method in a New User Model Form:
>
> save_model(self, request, obj, form, change)
>
> So you can:
>
> admin.site.unregister(User)
> admin.site.register(User, NewModelForm)
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/
>
> I hope this could help you!
>
> And finally the other way i usually use is extend a new Client Model
> from User, so i have a plenty access to the User Model
> and also from the request i get it through request.user.client and i
> override the save method for it.
>
> Regards,
>
> Sergio Hinojosa
>
> On Nov 27, 12:59 pm, bruno desthuilliers
>
> <[EMAIL PROTECTED]> wrote:
> > 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