090500
This commit is contained in:
@@ -1,3 +1,62 @@
|
||||
import logging
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
|
||||
# Register your models here.
|
||||
from config.accounts.models import User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProfileInline(admin.StackedInline):
|
||||
model = User
|
||||
can_delete = False
|
||||
max_num = 1
|
||||
verbose_name = 'Profile'
|
||||
|
||||
verbose_name_plural = 'Profile'
|
||||
fk_name = 'user'
|
||||
|
||||
|
||||
@admin.register(User)
|
||||
class UserAdmin(UserAdmin):
|
||||
ordering = ('email', )
|
||||
list_display = (
|
||||
'id', 'email', 'is_staff', 'is_superuser', 'is_active', 'date_joined', 'last_updated', 'last_login'
|
||||
)
|
||||
search_fields = ('email',)
|
||||
list_filter = (
|
||||
'is_staff', 'is_superuser', 'is_active',
|
||||
)
|
||||
readonly_fields = (
|
||||
'last_login', 'last_updated', 'date_joined'
|
||||
)
|
||||
list_display_links = ('id', 'email')
|
||||
fieldsets = (
|
||||
(None, {'fields': ('email', 'password')}),
|
||||
('Permissions', {'fields': ('groups', 'user_permissions')}),
|
||||
('Roles', {'fields': ('is_staff', 'is_superuser', 'is_active')}),
|
||||
('Profile', {'fields': (
|
||||
'username', 'first_name', 'last_name', 'gender', 'bio', 'address', 'followers'
|
||||
)}),
|
||||
('Dates', {'fields': ('last_login', 'last_updated', 'date_joined')})
|
||||
)
|
||||
add_fieldsets = (
|
||||
(None, {
|
||||
'classes': ('wide', ),
|
||||
'fields': (
|
||||
'email', 'password1', 'password2'
|
||||
)
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
"""код что отображает все модели всех apps
|
||||
|
||||
|
||||
models = apps.get_models()
|
||||
for model in models:
|
||||
try:
|
||||
admin.site.register(model)
|
||||
except admin.sites.AlreadyRegistered:
|
||||
pass
|
||||
"""
|
||||
|
||||
@@ -3,4 +3,5 @@ from django.apps import AppConfig
|
||||
|
||||
class AccountsConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'accounts'
|
||||
name = 'config.accounts'
|
||||
verbose_name = 'Управление пользователями'
|
||||
|
||||
46
config/accounts/migrations/0001_initial.py
Normal file
46
config/accounts/migrations/0001_initial.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# Generated by Django 4.2.13 on 2024-05-09 15:55
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='User',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||
('first_name', models.CharField(blank=True, max_length=60, null=True, verbose_name='Имя')),
|
||||
('last_name', models.CharField(blank=True, max_length=60, null=True, verbose_name='Фамилия')),
|
||||
('gender', models.CharField(choices=[('n', 'Не указано'), ('m', 'Мужчина'), ('f', 'Женщина')], default='n', max_length=10, verbose_name='Пол')),
|
||||
('email', models.EmailField(max_length=254, unique=True, verbose_name='Email Address')),
|
||||
('username', models.CharField(max_length=60, verbose_name='Ник')),
|
||||
('bio', models.TextField(blank=True, verbose_name='О себе')),
|
||||
('image', models.URLField(blank=True, null=True, verbose_name='Аватар')),
|
||||
('address', models.CharField(blank=True, max_length=255, null=True, verbose_name='Адрес')),
|
||||
('date_joined', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Дата регистрации')),
|
||||
('last_updated', models.DateTimeField(auto_now=True, null=True, verbose_name='Последнее обновление')),
|
||||
('last_login', models.DateTimeField(auto_now=True, null=True, verbose_name='Последняя авторизация')),
|
||||
('status', models.BooleanField(default=False, verbose_name='Статус')),
|
||||
('followers', models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL, verbose_name='Подписчики')),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'user',
|
||||
'verbose_name_plural': 'users',
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user