diff --git a/core/apps/accounts/management/commands/seed_permissions.py b/core/apps/accounts/management/commands/seed_permissions.py new file mode 100644 index 0000000..4fcd1ec --- /dev/null +++ b/core/apps/accounts/management/commands/seed_permissions.py @@ -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']}")) + \ No newline at end of file diff --git a/core/apps/accounts/urls.py b/core/apps/accounts/urls.py index 56a2925..1a479ca 100644 --- a/core/apps/accounts/urls.py +++ b/core/apps/accounts/urls.py @@ -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()), ] \ No newline at end of file