mirror of
https://github.com/thecyberlearn/modern-django-starter.git
synced 2026-08-18 16:52:55 +00:00
✨ Features: - Complete Django project with authentication - Email/password and social login (Google, Facebook) - Role-based access control (admin, staff, user) - Docker and Docker Compose setup - Production-ready configuration - Static file handling with WhiteNoise - PostgreSQL database integration - Comprehensive documentation - GitHub CI/CD workflows - Dokploy deployment configuration 🚀 Ready for deployment on Dokploy, Heroku, Railway, and other platforms
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
from django.contrib import admin
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
|
from django.contrib.auth.models import Group
|
|
from .models import User, UserProfile
|
|
|
|
|
|
class UserProfileInline(admin.StackedInline):
|
|
model = UserProfile
|
|
can_delete = False
|
|
verbose_name_plural = 'Profile'
|
|
|
|
|
|
@admin.register(User)
|
|
class UserAdmin(BaseUserAdmin):
|
|
inlines = (UserProfileInline,)
|
|
list_display = ('email', 'username', 'first_name', 'last_name', 'is_staff', 'is_verified', 'created_at')
|
|
list_filter = ('is_staff', 'is_superuser', 'is_active', 'is_verified', 'groups')
|
|
search_fields = ('email', 'username', 'first_name', 'last_name')
|
|
ordering = ('email',)
|
|
filter_horizontal = ('groups', 'user_permissions')
|
|
|
|
fieldsets = (
|
|
(None, {'fields': ('email', 'password')}),
|
|
('Personal info', {'fields': ('username', 'first_name', 'last_name')}),
|
|
('Permissions', {
|
|
'fields': ('is_active', 'is_staff', 'is_superuser', 'is_verified', 'groups', 'user_permissions'),
|
|
}),
|
|
('Important dates', {'fields': ('last_login', 'date_joined')}),
|
|
)
|
|
|
|
add_fieldsets = (
|
|
(None, {
|
|
'classes': ('wide',),
|
|
'fields': ('email', 'username', 'first_name', 'last_name', 'password1', 'password2'),
|
|
}),
|
|
)
|
|
|
|
def get_inline_instances(self, request, obj=None):
|
|
if not obj:
|
|
return list()
|
|
return super().get_inline_instances(request, obj)
|
|
|
|
|
|
@admin.register(UserProfile)
|
|
class UserProfileAdmin(admin.ModelAdmin):
|
|
list_display = ('user', 'location', 'birth_date')
|
|
search_fields = ('user__email', 'user__first_name', 'user__last_name')
|
|
list_filter = ('location',) |