I'm not sure how to solve your exact problem but I would recommend NOT extending the user class here.
You'll probably want to create a manytomany field on your Course model that contains users. And if you're going to have many different types of users you'll want to create groups. Put students in the 'students' group. Mainly, I just don't think you're subclassing User for the right reasons. In fact, I can't really think of anytime I would subclass it. Usually adding a related table is a better way to go (lookup django user profiles for example). On Sep 24, 12:29 am, Axel <mr.axel.b...@gmail.com> wrote: > All right, I found some > sources.http://stackoverflow.com/questions/1061279/for-the-django-admin-how-d...http://blog.picante.co.nz/post/Subclassing-User-to-add-extra-fields-i... > > By strictly holding to these, and by experimenting, I now get this: > > _'StudentAdmin.fieldsets[0][1]['fields']' refers to field 'course' > that is missing from the form._ > > Adding a class StudentCreateForm(UserCreationForm) does not help, > either: > > class StudentCreateForm(UserCreationForm): > course = forms.CharField() > class StudentAdmin(UserAdmin): > # ... > add_form = StudentCreateForm > > Please, I am going crazy. There's probably a super-simple solution, > but I don't seem to find it. And I feel horribly stupid right now. And > it's several hours now, cause I can't let go - and I'm horribly tired. > > Thanks, > Axel. > > On Sep 23, 11:29 pm, Axel Bock <mr.axel.b...@gmail.com> wrote: > > > Hello all, > > > I must admit - I am going crazy. With something I thought should be > > incredibly simple, but maybe I am just too f**king stupid. > > > All right, here comes my problem. I have subclassed "User" as "Student" and > > added some required fields, one of them being "Course": > > > # models.py > > class Student(User): > > course = models.ForeignKey('Course') > > > So far, so good. Now I couldn't create a Student with an initial password - > > the password field was plaintext, and the "change password" form wouldn't > > work. I dug through the code and some postings, and discovered that if I > > used a custom admin class it would just work fine, with the advantage that I > > could exclude some fields I don't need in the admin view of the Students. > > That basically looks like this: > > > # admin.py > > class StudentAdmin(UserAdmin): > > fieldsets = ( #... > > ) > > admin.site.register(Student, StudentAdmin) > > * > > Then* I got another annoyance. If I tried to create a Student now, I was > > confronted with the "usual" User creation screen. (Huh? ... ok, dig a bit in > > Django internals, one can only learn ...). Basically I wouldnt mind, but the > > Student creation does not work any more - the simple add user screen will of > > course set no "course" value in the Student model, So I dug further. I > > discovered that the user creation was handled by a form called > > UserCreationForm, and this form explicitly excluded alot of stuff. > > > But now the magic went crazy. If I look at the UserCreationForm class, I > > see: > > > class Meta: > > model = User > > fields = ("username",) > > > WTF? The only field which *should* be seen is "username", according to the > > docs (according > > tohttp://docs.djangoproject.com/en/1.2/topics/forms/modelforms/). But there > > is > > password AND username. Aha. I am pretty confused now. But not without > > optimism. I tried subclassing the form now, which looked something like > > this: > > > *class StudentCreationForm(UserCreationForm): > > class Meta(): > > model = Student > > fields = ('course') > > * > > class StudentAdmin(UserAdmin): > > #fields = ('first_name', 'family_name', 'password', 'course', 'base') > > fieldsets = ( # ... cut out > > *add_form = StudentCreationForm* > > > And the result? No luck. WhatEVER I do (replacing UserCreationForm with > > subclass of ModelForm, overriding get_form(), and some other things), the > > form will only and inevitably show "username" and "password". > > > And it's about two hours now. > > > Help. > > > Please. > > > Thanks! > > Axel. > > -- 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.