"UserCreationForm<https://docs.djangoproject.com/en/1.5/topics/auth/default/#django.contrib.auth.forms.UserCreationForm>

Depends on the 
User<https://docs.djangoproject.com/en/1.5/ref/contrib/auth/#django.contrib.auth.models.User>
 model. 
Must be re-written for any custom user model."
I swore I RTM'ed :).  Thanks!

I think it really doesn't depend on the User model - my class inherits from 
AbstractUser.  I think with the one modification I made, it works fine.  I 
think just a check in the form to see if AUTH_USER_MODEL is defined, and if 
so use that class instead of direct references to the User class would make 
it work 100% for any class that inherits from AbstractUser.

I've made no change to the UserChangeForm and it is working fine - in fact 
I've extended it somewhat by adding fields and such in my class that 
inherits AdminUser - everything working as expected in my Admin interface.

I mainly did this to keep using the built-in password hash functions, 
password reset, etc without having to maintain my own copy of it.

On Wednesday, February 27, 2013 1:43:27 PM UTC-6, sacrac wrote:
>
> check the docu
>
> https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#custom-users-and-the-built-in-auth-forms
>
> Cheers
>
>
> On Wed, Feb 27, 2013 at 1:15 PM, Eric Psalmond <epsa...@gmail.com<javascript:>
> > wrote:
>
>> Hi everyone,
>>
>> After a bit of searching I didn't find an answer to this issue, so I 
>> thought I'd post here and see what the response was like.
>>
>> A little background:  I've been working with other frameworks and 
>> packages for years - from Websphere long ago to RoR and M$-MVC more 
>> recently.
>>
>> After using Django for about two weeks I'm 100% in love with it and have 
>> been singing its praises from the mountaintops.  Documentation is dead on 
>> and unlike anything else I've seen, and the ORM is for people that actually 
>> understand and like RDBMS, and in a day and age of No-SQL fads and PHP 
>> "developers," it has been very refreshing.  I was trying out Django 
>> alongside with a trendy new PHP framework that claimed to have great docs 
>> and ORM, but when implementing it I found it was a typical mess of 
>> documentation-by-forum and uniquely seemed to love the smell of its own 
>> farts more than any open source project I'd ever seen.
>>
>> If I had one complaint about Django, it would be lack of support for 
>> composite keys,  but I see enough work has already been done on that front 
>> that I might feel comfortable hacking something together, and it's so minor 
>> compared to all the other benefits that I can live with it.
>>
>> Anyway- on to my question:
>>
>> I rolled a custom user model since 1.5 was released yesterday.  I love 
>> the abstractions of AbstractUser and AbstractBaseUser, it totally makes 
>> sense.  However, when I rolled my own custom user class and tried to use 
>> the built in UserAdmin and UserCreationForm classes, I had a problem with 
>> the Admin.  Everything in my project seemed to obey the swappable Meta tag 
>> in the User class except for the UserCreationForm.  I always got an error 
>> of:  Table does not exist: "auth_user" whenever getting past the first step 
>> of setting username and password.
>>
>> Not being super familiar with forms in Django yet, I stepped through the 
>> debugger and found that this line in the form was the culprit:
>>
>>  def clean_username(self):
>>         # Since User.username is unique, this check is redundant,
>>         # but it sets a nicer error message than the ORM. See #13147.
>>         username = self.cleaned_data["username"]
>>          try:
>>             User._default_manager.get(username=username)
>>         except User.DoesNotExist:
>>             return username
>>         raise 
>> forms.ValidationError(self.error_messages['duplicate_username'])
>>
>> For some reason, User._default_manager.get refused to obey the switch the 
>> my CustomUser class.  User.anything_else seemed to be OK.  I resolved this 
>> by changing User._default_manager.get to my CustomUser._default_manager.get 
>> and now everything is peachy and going to the right table.
>>
>> I have seen some posts that indicate when using a custom user class that 
>> new forms and UserAdmin classes must be rolled (or, *gasp*, copy-pasted,) 
>> so I'm wondering if this is the expected and correct behavior, am I missing 
>> something, or did I find a bug?
>>
>> Thanks for reading and I look forward to participating in this awesome 
>> community.
>>
>> Best,
>> -Eric
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>

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


Reply via email to