user password change working in admin
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.contrib.auth.admin import UserAdmin
|
||||||
|
|
||||||
from .forms import CustomUserChangeForm, CustomUserCreationForm
|
from django.contrib.auth.forms import AdminPasswordChangeForm
|
||||||
|
|
||||||
from . import models
|
|
||||||
from .forms import CustomUserChangeForm, CustomUserCreationForm
|
from .forms import CustomUserChangeForm, CustomUserCreationForm
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ from django.contrib.auth import get_user_model
|
|||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
class UserAdmin(admin.ModelAdmin):
|
class UserAdmin(UserAdmin):
|
||||||
add_form = CustomUserCreationForm
|
add_form = CustomUserCreationForm
|
||||||
form = CustomUserChangeForm
|
form = CustomUserChangeForm
|
||||||
model = User
|
model = User
|
||||||
@@ -19,6 +19,7 @@ class UserAdmin(admin.ModelAdmin):
|
|||||||
list_display = ('email', 'full_name', 'role', 'company', 'email_verified', 'is_active', 'is_staff', 'created', 'last_visit')
|
list_display = ('email', 'full_name', 'role', 'company', 'email_verified', 'is_active', 'is_staff', 'created', 'last_visit')
|
||||||
list_filter = ('is_active', 'is_staff', 'email_verified')
|
list_filter = ('is_active', 'is_staff', 'email_verified')
|
||||||
search_fields = ('email', 'full_name', 'company__short_name')
|
search_fields = ('email', 'full_name', 'company__short_name')
|
||||||
|
readonly_fields = ['modified','created','last_visit']
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, {'fields': ('email', 'password','full_name', 'role', 'notify','provider','email_verified','company','is_active')}),
|
(None, {'fields': ('email', 'password','full_name', 'role', 'notify','provider','email_verified','company','is_active')}),
|
||||||
@@ -28,8 +29,11 @@ class UserAdmin(admin.ModelAdmin):
|
|||||||
add_fieldsets = (
|
add_fieldsets = (
|
||||||
(None, {
|
(None, {
|
||||||
'classes': ('wide',),
|
'classes': ('wide',),
|
||||||
'fields': ('email', 'password1', 'password2', 'is_staff', 'is_active')}
|
'fields': ('email', 'password1', 'password2', 'full_name', 'role', 'company', 'email_verified', 'is_active', 'is_staff')}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
admin.site.register(models.CustomUser, UserAdmin)
|
ordering = ('email',)
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(User, UserAdmin)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
|
from django.contrib.auth.forms import UserChangeForm, UserCreationForm, AdminPasswordChangeForm
|
||||||
from django.forms import ModelForm
|
from django.forms import ModelForm
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
@@ -9,7 +9,6 @@ User = get_user_model()
|
|||||||
class CustomUserCreationForm(UserCreationForm):
|
class CustomUserCreationForm(UserCreationForm):
|
||||||
|
|
||||||
class Meta(UserCreationForm.Meta):
|
class Meta(UserCreationForm.Meta):
|
||||||
|
|
||||||
model = User
|
model = User
|
||||||
|
|
||||||
UserCreationForm.Meta.fields = ('email',)
|
UserCreationForm.Meta.fields = ('email',)
|
||||||
@@ -21,7 +20,6 @@ class CustomUserChangeForm(UserChangeForm):
|
|||||||
|
|
||||||
class Meta(UserChangeForm.Meta):
|
class Meta(UserChangeForm.Meta):
|
||||||
model = User
|
model = User
|
||||||
|
|
||||||
UserChangeForm.Meta.fields = ('email',)
|
UserChangeForm.Meta.fields = ('email',)
|
||||||
fields = UserChangeForm.Meta.fields + ('full_name','role', 'notify', 'provider', 'email_verified', 'company', 'is_active', 'is_staff')
|
fields = UserChangeForm.Meta.fields + ('full_name','role', 'notify', 'provider', 'email_verified', 'company', 'is_active', 'is_staff')
|
||||||
UserChangeForm.Meta.fields = ('password1','password2',)
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user