From 5fbf77e0149406632f01ac9a3b1abbb8a7b5aa44 Mon Sep 17 00:00:00 2001 From: Christopher Charbonneau Wells Date: Sun, 22 Oct 2017 16:50:47 -0400 Subject: [PATCH] Override migrate command to create admin/admin user. --- README.md | 4 +++- babybuddy/management/commands/migrate.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 babybuddy/management/commands/migrate.py diff --git a/README.md b/README.md index 6f2706d8..a368fafc 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,14 @@ pip install pipenv pipenv install --dev pipenv shell python manage.py migrate -python manage.py createsuperuser npm install gulp build python manage.py runserver ``` +Open [http://127.0.0.1:8000](http://127.0.0.1:8000) and log in with the default +user name and password (admin/admin). + ## Development ### Fake data diff --git a/babybuddy/management/commands/migrate.py b/babybuddy/management/commands/migrate.py new file mode 100644 index 00000000..1bccb17f --- /dev/null +++ b/babybuddy/management/commands/migrate.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib.auth.models import User +from django.core.management.commands import migrate + + +class Command(migrate.Command): + help = 'Creates an initial User (admin/admin) for Baby Buddy.' + + def handle(self, *args, **kwargs): + super(Command, self).handle(*args, **kwargs) + + superusers = User.objects.filter(is_superuser=True) + if len(superusers) == 0: + default_user = User.objects.create_user('admin', password='admin') + default_user.is_superuser = True + default_user.is_staff = True + default_user.save()