I want to change the behavior of what happens when you add User
objects in the admin.

I subclassed the User object and added a custom manager that changes
the behavior of create_user.

Then I created a ModelAdmin corresponding to this subclassed User and
registered them together with the admin.

The trouble is, when I create a user, nothing different happens.

The message "In MyUserManager" should be printed out, but it's not.

I've posted the code below.

Does anyone see any mistakes? Or is there any hooks I'm missing or
holes in my logic?


Thanks,

Jacob


=models.py
from django.contrib.auth.models import User
from django.contrib.auth.models import UserManager
from django.utils.translation import ugettext_lazy as _

class MyUserManager(UserManager):
    def create_user(self, username, email, password=None):
        """
        Creates and saves a User with the given username, e-mail and password.
        """
        print "In MyUserManager"
        now = datetime.datetime.now()

        # Normalize the address by lowercasing the domain part of the email
        # address.
        try:
            email_name, domain_part = email.strip().split('@', 1)
        except ValueError:
            pass
        else:
            email = '@'.join([email_name, domain_part.lower()])

        user = self.model(username=username, email=email, is_staff=True,
                         is_active=True, is_superuser=False, last_login=now,
                         date_joined=now)

        if password:
            user.set_password(password)
        else:
            user.set_unusable_password()
        user.save(using=self._db)
        return user

class MyUser(User):
    objects = MyUserManager()


=admin.py
from django.utils.translation import ugettext_lazy as _
from myapp.models import MyUser

class MyUserAdmin(MyUserAdmin):
    pass

admin.site.register(MyUser, MyUserAdmin)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to