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 to
http://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 [email protected].
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.