-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create user and experiment on startup
- Loading branch information
1 parent
f084edd
commit c1c36a6
Showing
4 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.core import management | ||
from django.core.management.base import BaseCommand | ||
from django.contrib.auth.models import User | ||
|
||
from experiment.models import Experiment | ||
from section.models import Playlist | ||
|
||
class Command(BaseCommand): | ||
""" Command for creating a superuser and an experiment if they do not yet exist """ | ||
|
||
def handle(self, *args, **options): | ||
if User.objects.count() == 0: | ||
management.call_command('createsuperuser', '--no-input') | ||
logger.info('Created superuser') | ||
if Experiment.objects.count() == 0: | ||
playlist = Playlist.objects.create( | ||
name='Empty Playlist' | ||
) | ||
experiment = Experiment.objects.create( | ||
name='Goldsmiths Musical Sophistication Index', | ||
rules='GOLD_MSI', | ||
slug='gold-msi', | ||
) | ||
experiment.playlists.add(playlist) | ||
print('Created default experiment') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters