from django.contrib.auth.admin import UserAdmin

from .forms import UserCreationForm, UserChangeForm


class UserAdmin(UserAdmin):
    form = UserChangeForm
    add_form = UserCreationForm

    fieldsets = (
        (None, {'fields': ('email', 'password',)}),
        ('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser',)}),
        ('Groups', {'fields': ('groups', 'user_permissions',)}),
    )

    add_fieldsets = (
        (None, {'classes': ('wide',),
                'fields': ('email', 'password1', 'password2')}),
    )

    list_display = ('email', )
    list_filter = ('is_active', )
    search_fields = ('email',)
    ordering = ('email',)

from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _

from .forms import UserCreationForm, UserChangeForm


class UserAdmin(UserAdmin):
    form = UserChangeForm
    add_form = UserCreationForm

    fieldsets = (
        (None, {'fields': ('email', 'password', 'two_fa_enabled')}),
        (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',)}),
        (_('Groups'), {'fields': ('groups', 'user_permissions',)}),
        (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
    )

    add_fieldsets = (
        (None, {'classes': ('wide',),
                'fields': ('email', 'password1', 'password2')}),
    )

    list_display = ('email', )
    list_filter = ('is_active', )
    search_fields = ('email',)
    ordering = ('email',)

Add 2FA field, use localized labels in UserAdmin
Add 2FA field, use localized labels in UserAdmin

  from django.contrib.auth.admin import UserAdmin
+ from django.utils.translation import ugettext_lazy as _
  
  from .forms import UserCreationForm, UserChangeForm
  
  
  class UserAdmin(UserAdmin):
      form = UserChangeForm
      add_form = UserCreationForm
  
      fieldsets = (
-         (None, {'fields': ('email', 'password',)}),
+         (None, {'fields': ('email', 'password', 'two_fa_enabled')}),
-         ('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser',)}),
+         (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',)}),
-         ('Groups', {'fields': ('groups', 'user_permissions',)}),
+         (_('Groups'), {'fields': ('groups', 'user_permissions',)}),
+         (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
      )
  
      add_fieldsets = (
          (None, {'classes': ('wide',),
                  'fields': ('email', 'password1', 'password2')}),
      )
  
      list_display = ('email', )
      list_filter = ('is_active', )
      search_fields = ('email',)
      ordering = ('email',)
  
Add 2FA field, use localized labels in UserAdmin
## Code Before:
from django.contrib.auth.admin import UserAdmin

from .forms import UserCreationForm, UserChangeForm


class UserAdmin(UserAdmin):
    form = UserChangeForm
    add_form = UserCreationForm

    fieldsets = (
        (None, {'fields': ('email', 'password',)}),
        ('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser',)}),
        ('Groups', {'fields': ('groups', 'user_permissions',)}),
    )

    add_fieldsets = (
        (None, {'classes': ('wide',),
                'fields': ('email', 'password1', 'password2')}),
    )

    list_display = ('email', )
    list_filter = ('is_active', )
    search_fields = ('email',)
    ordering = ('email',)

## Instruction:
Add 2FA field, use localized labels in UserAdmin
## Code After:
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _

from .forms import UserCreationForm, UserChangeForm


class UserAdmin(UserAdmin):
    form = UserChangeForm
    add_form = UserCreationForm

    fieldsets = (
        (None, {'fields': ('email', 'password', 'two_fa_enabled')}),
        (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',)}),
        (_('Groups'), {'fields': ('groups', 'user_permissions',)}),
        (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
    )

    add_fieldsets = (
        (None, {'classes': ('wide',),
                'fields': ('email', 'password1', 'password2')}),
    )

    list_display = ('email', )
    list_filter = ('is_active', )
    search_fields = ('email',)
    ordering = ('email',)
