Merge branch 'development' of https://bitbucket.org/enreda/back-latienda into development

This commit is contained in:
Diego Calvo
2021-03-25 15:17:24 +01:00
2 changed files with 50 additions and 1 deletions

View File

@@ -1,13 +1,35 @@
from django.contrib import admin
from .forms import CustomUserChangeForm, CustomUserCreationForm
from . import models
from .forms import CustomUserChangeForm, CustomUserCreationForm
# Register your models here.
from django.contrib.auth import get_user_model
User = get_user_model()
class UserAdmin(admin.ModelAdmin):
add_form = CustomUserCreationForm
form = CustomUserChangeForm
model = User
list_display = ('email', 'full_name', 'role', 'company', 'email_verified', 'is_active', 'is_staff', 'created', 'last_visit')
list_filter = ('is_active', 'is_staff', 'email_verified')
search_fields = ('email', 'full_name', 'company')
search_fields = ('email', 'full_name', 'company__short_name')
fieldsets = (
(None, {'fields': ('email', 'password','full_name', 'role', 'notify','provider','email_verified','company','is_active')}),
('Permissions', {'fields': ('is_staff', 'groups')}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'password1', 'password2', 'is_staff', 'is_active')}
),
)
admin.site.register(models.CustomUser, UserAdmin)

27
core/forms.py Normal file
View File

@@ -0,0 +1,27 @@
from django import forms
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.forms import ModelForm
from django.contrib.auth import get_user_model
User = get_user_model()
class CustomUserCreationForm(UserCreationForm):
class Meta(UserCreationForm.Meta):
model = User
UserCreationForm.Meta.fields = ('email',)
fields = UserCreationForm.Meta.fields + ('full_name','role', 'notify', 'provider', 'email_verified', 'company', 'is_active', 'is_staff')
UserCreationForm.Meta.fields = ('password1','password2',)
class CustomUserChangeForm(UserChangeForm):
class Meta(UserChangeForm.Meta):
model = User
UserChangeForm.Meta.fields = ('email',)
fields = UserChangeForm.Meta.fields + ('full_name','role', 'notify', 'provider', 'email_verified', 'company', 'is_active', 'is_staff')
UserChangeForm.Meta.fields = ('password1','password2',)