ソースを参照

Create superuser command

kaajavi 5 年 前
コミット
a684319e74

+ 1 - 1
Readme.md

@@ -2,7 +2,7 @@
 
 Author: Javier Guignard
 
-You can see demo in challenge.kaajavi.com
+You can see demo in https://demo.kaajavi.com/
 
 ## Setup
 

+ 0 - 0
users/management/__init__.py


+ 0 - 0
users/management/commands/__init__.py


+ 19 - 0
users/management/commands/create_superuser.py

@@ -0,0 +1,19 @@
+"""
+This command create superuser object.
+Run with>
+python manage.py create_superuser users
+"""
+
+from django.core.management.base import AppCommand
+from users.models import User
+
+
+class Command(AppCommand):
+
+    def handle(self, *args, **options):
+        if User.objects.filter(email='admin@admin.com').count() < 1:
+            u = User(email='admin@admin.com', name='Administrator', age=18,
+                     is_staff=True, is_superuser=True, is_active=True)
+            u.set_password('admin')
+            u.save()
+            print('User admin created')