Opened 6 years ago

Closed 6 years ago

#30139 closed Bug (invalid)

django.contrib.auth.forms.UserCreationForm() doesn't call default manager's create_user()

Reported by: Ashish Mohite Owned by: nobody
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

While defining custom manager to the User model we usually override two methods create_user and create_superuser but those methods don't get called when you try to create user using django admin. I'm not sure where else create_user method is being used apart from tests in django source.

I want to change the email case while creating the email so i've overridden create_user method but it doesn't work(I know save override would be the alternative to this but wanted to know the reason why create_user isn't be being used while creating user in django admin)

Change History (1)

comment:1 by Carlton Gibson, 6 years ago

Resolution: invalid
Status: newclosed

Hi.

This is more of a question than a bug report. It might have been better targeted (at least initially) at the django-users or similar.

However...

I don't think there's much we can do here. The long and short is, that's just how model forms work: they instantiate an instance of the model, update attributes on that, and call save(), rather than using manager create() style helpers. (That's not something that's realistically going to change I think.)

You could, in your own project override the default admin and provide an add_form that used your create_user and so on. (No doubt there'd be wiggles.)
That's beyond the scope of help we can provide here I'm afraid.
Good luck. Have fun.

Note: See TracTickets for help on using tickets.
Back to Top