SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 001fa430 authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Add management command to populate db with initial data

parent 53fe34a5
No related branches found
No related tags found
No related merge requests found
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from ...models import Contributor from ...factories import EditorialCollegeFactory, EditorialCollegeMemberFactory
class Command(BaseCommand): class Command(BaseCommand):
def add_arguments(self, parser): def create_editorial_college(self):
parser.add_argument( EditorialCollegeFactory.create_batch(5)
'--username', type=str, required=True, self.stdout.write(self.style.SUCCESS('Successfully created Editorial College\'s.'))
help='Username of user to use for contributor model')
def create_contributor(self, username): def create_editorial_college_members(self):
user = User.objects.get(username=username) EditorialCollegeMemberFactory.create_batch(20)
contributor = Contributor(user=user, status=1, title="MR") self.stdout.write(self.style.SUCCESS('Successfully created Editorial College Members.'))
contributor.vetted_by = contributor
contributor.save()
def handle(self, *args, **options): def handle(self, *args, **kwargs):
self.create_contributor(options['username']) self.create_editorial_college()
self.create_editorial_college_members()
from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
from ...models import Contributor
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
'--username', type=str, required=True,
help='Username of user to use for contributor model')
def create_contributor(self, username):
user = User.objects.get(username=username)
contributor = Contributor(user=user, status=1, title="MR")
contributor.vetted_by = contributor
contributor.save()
def handle(self, *args, **options):
self.create_contributor(options['username'])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment