mirror of
https://github.com/Balshgit/different
synced 2025-09-11 02:50:41 +03:00
accounts app redirections
This commit is contained in:
parent
bef1e8a9f1
commit
7da2982b54
@ -53,9 +53,11 @@ EMAIL_USE_TLS=
|
||||
|
||||
## To urls.py
|
||||
|
||||
from health_check import urls as health_urls
|
||||
from server.apps.accounts import urls as accounts_urls
|
||||
|
||||
url_patterns
|
||||
|
||||
path('accounts/', include(accounts_urls)),
|
||||
path('admin/login/', login_required(lambda request: redirect('accounts/login/', permanent=True),
|
||||
redirect_field_name='admin/login/?next=')),
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
from server.apps.accounts.models import CustomUser, CustomGroup
|
||||
from server.apps.accounts.models import CustomUser
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin, GroupAdmin, Group
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
|
||||
|
||||
@admin.register(CustomUser)
|
||||
@ -38,11 +38,3 @@ class CustomUserAdmin(UserAdmin):
|
||||
|
||||
search_fields = ('username', 'first_name', 'last_name', 'mobile', 'email')
|
||||
filter_horizontal = ('groups', 'user_permissions',)
|
||||
|
||||
|
||||
admin.site.unregister(Group)
|
||||
|
||||
|
||||
@admin.register(CustomGroup)
|
||||
class CustomGroupAdmin(GroupAdmin):
|
||||
...
|
||||
|
19
django_accounts_app/management/commands/create_admin.py
Normal file
19
django_accounts_app/management/commands/create_admin.py
Normal file
@ -0,0 +1,19 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
from server.apps.accounts.models import CustomUser
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if not CustomUser.objects.filter(username='admin').exists():
|
||||
username = 'admin'
|
||||
email = 'admin@admin.ru'
|
||||
password = 'admin'
|
||||
admin = CustomUser.objects.create_superuser(username=username,
|
||||
password=password,
|
||||
email=email)
|
||||
admin.is_active = True
|
||||
admin.is_admin = True
|
||||
admin.save()
|
||||
else:
|
||||
print('Admin accounts can only be initialized if no Accounts exist')
|
@ -16,20 +16,6 @@ class Migration(migrations.Migration):
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CustomGroup',
|
||||
fields=[
|
||||
('group_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='auth.group')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Permissions group',
|
||||
'verbose_name_plural': 'Permissions groups',
|
||||
},
|
||||
bases=('auth.group',),
|
||||
managers=[
|
||||
('objects', django.contrib.auth.models.GroupManager()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='CustomUser',
|
||||
fields=[
|
||||
|
@ -1,5 +1,5 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import AbstractUser, Group
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from .managers import CustomUserManager
|
||||
|
||||
|
||||
@ -18,9 +18,3 @@ class CustomUser(AbstractUser):
|
||||
|
||||
def __str__(self):
|
||||
return self.username
|
||||
|
||||
|
||||
class CustomGroup(Group):
|
||||
class Meta:
|
||||
verbose_name = 'Permissions group'
|
||||
verbose_name_plural = 'Permissions groups'
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
from django.urls import path, include
|
||||
from .views import dashboard, RegisterUser
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user