update
This commit is contained in:
47
accounts/admin.py
Normal file
47
accounts/admin.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""
|
||||
Admin configuration for accounts app.
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
||||
from .models import User, UserProfile, ActivityLog, FailedLoginAttempt
|
||||
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(BaseUserAdmin):
|
||||
"""Custom user admin."""
|
||||
list_display = ('username', 'email', 'role', 'is_verified', 'is_active', 'created_at')
|
||||
list_filter = ('role', 'is_verified', 'is_active', 'created_at')
|
||||
fieldsets = BaseUserAdmin.fieldsets + (
|
||||
('Additional Info', {'fields': ('role', 'is_verified', 'mfa_enabled', 'last_login_ip')}),
|
||||
)
|
||||
add_fieldsets = BaseUserAdmin.add_fieldsets + (
|
||||
('Additional Info', {'fields': ('role', 'is_verified')}),
|
||||
)
|
||||
|
||||
|
||||
@admin.register(UserProfile)
|
||||
class UserProfileAdmin(admin.ModelAdmin):
|
||||
"""User profile admin."""
|
||||
list_display = ('user', 'first_name', 'last_name', 'consent_given', 'preferred_language')
|
||||
list_filter = ('consent_given', 'preferred_language')
|
||||
search_fields = ('user__username', 'user__email', 'first_name', 'last_name')
|
||||
|
||||
|
||||
@admin.register(ActivityLog)
|
||||
class ActivityLogAdmin(admin.ModelAdmin):
|
||||
"""Activity log admin."""
|
||||
list_display = ('user', 'action', 'ip_address', 'timestamp')
|
||||
list_filter = ('action', 'timestamp')
|
||||
search_fields = ('user__username', 'ip_address')
|
||||
readonly_fields = ('user', 'action', 'ip_address', 'user_agent', 'details', 'timestamp')
|
||||
date_hierarchy = 'timestamp'
|
||||
|
||||
|
||||
@admin.register(FailedLoginAttempt)
|
||||
class FailedLoginAttemptAdmin(admin.ModelAdmin):
|
||||
"""Failed login attempt admin."""
|
||||
list_display = ('email_or_username', 'ip_address', 'timestamp', 'is_blocked')
|
||||
list_filter = ('is_blocked', 'timestamp')
|
||||
search_fields = ('email_or_username', 'ip_address')
|
||||
readonly_fields = ('email_or_username', 'ip_address', 'user_agent', 'timestamp')
|
||||
date_hierarchy = 'timestamp'
|
||||
Reference in New Issue
Block a user