Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create custom user form

Tags:

On Django Admin, the default 'create user' form has 3 fields: username, password and confirm password.

I need to customize the create user form. I want to add the firstname and lastname fields, and autofill the username field with firstname.lastname.

How can I do this?

like image 703
bleroy Avatar asked Mar 06 '15 11:03

bleroy


People also ask

How do you create a user form?

To create a UserForm, click UserForm on the Insert menu in the Visual Basic Editor. Use the Properties window to change the name, behavior, and appearance of the form. For example, to change the caption on a form, set the Caption property.

How do I create a UserForm in VBA?

Step 1 − Navigate to VBA Window by pressing Alt+F11 and Navigate to "Insert" Menu and select "User Form". Upon selecting, the user form is displayed as shown in the following screenshot. Step 2 − Design the forms using the given controls. Step 3 − After adding each control, the controls have to be named.

What is a user form?

A UserForm object is a window or dialog box that makes up part of an application's user interface. The UserForms collection is a collection whose elements represent each loaded UserForm in an application. The UserForms collection has a Count property, an Item method, and an Add method.


1 Answers

Something like this should work:

from django.contrib import admin from django.contrib.auth.admin import UserAdmin from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User  class UserCreateForm(UserCreationForm):      class Meta:         model = User         fields = ('username', 'first_name' , 'last_name', )   class UserAdmin(UserAdmin):     add_form = UserCreateForm     prepopulated_fields = {'username': ('first_name' , 'last_name', )}      add_fieldsets = (         (None, {             'classes': ('wide',),             'fields': ('first_name', 'last_name', 'username', 'password1', 'password2', ),         }),     )   # Re-register UserAdmin admin.site.unregister(User) admin.site.register(User, UserAdmin) 
like image 159
mishbah Avatar answered Oct 26 '22 16:10

mishbah