add management command for accounts

This commit is contained in:
behruz-dev
2025-08-01 10:30:53 +05:00
parent 0a2127d826
commit e8d525ef96
2 changed files with 27 additions and 2 deletions

View File

@@ -0,0 +1,26 @@
from django.core.management.base import BaseCommand
from core.apps.accounts.models.permission import Permission
class Command(BaseCommand):
help = "Creates intial permission entries"
def handle(self, *args, **options):
permissions = [
{"code": "can_see_product_wherehouse", "name": "permission for see wherehouse list"},
{
"code": "can_add_product_wherehouse",
"name": "permission for add product in wherehouse"
}
]
for perm in permissions:
obj, created = Permission.objects.get_or_create(
code=perm['code'], name=perm['name']
)
if created:
self.stdout.write(self.style.SUCCESS(f"Created: {perm['code']}"))
else:
self.stdout.write(self.style.WARNING(f"Already exists: {perm['code']}"))

View File

@@ -1,8 +1,7 @@
from django.urls import path, include
from core.apps.accounts.views.login import LoginApiView, TestApiView
from core.apps.accounts.views.login import LoginApiView
urlpatterns = [
path('auth/login/', LoginApiView.as_view(), name='login'),
path('test/', TestApiView.as_view()),
]