Override migrate command to create admin/admin user.

This commit is contained in:
Christopher Charbonneau Wells 2017-10-22 16:50:47 -04:00
parent 68d2e7f37c
commit 5fbf77e014
2 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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()