Skip to content
Snippets Groups Projects
Commit 6932ce35 authored by fu2662cw's avatar fu2662cw :speech_balloon:
Browse files

Add seed as a argument to seed_db command

parent c12d70e0
No related branches found
No related tags found
No related merge requests found
...@@ -74,9 +74,10 @@ If successful, you can now see the running server in your browser at `http://127 ...@@ -74,9 +74,10 @@ If successful, you can now see the running server in your browser at `http://127
## Populate the database with test data ## Populate the database with test data
To populate the database with some test data run To populate the database with some test data run
``` ```
python manage.py seed_db python manage.py seed_db [-y] [--seed SEED]
``` ```
All the existing data from your database will be lost! All the existing data from your database will be lost!
Run `python manage.py seed_db --help` for more information.
## Use the django admin interface to view and edit data during development ## Use the django admin interface to view and edit data during development
If you started the server as described above, you can access the django admin interface on If you started the server as described above, you can access the django admin interface on
......
...@@ -39,6 +39,13 @@ class Command(BaseCommand): ...@@ -39,6 +39,13 @@ class Command(BaseCommand):
help="Don't ask to confirm database flushing", help="Don't ask to confirm database flushing",
) )
parser.add_argument(
"--seed",
type=int,
default=42,
help="Optional seed for random generator. Defaults to 42",
)
def handle(self, *args, **options): def handle(self, *args, **options):
"""Create some objects for all models""" """Create some objects for all models"""
...@@ -49,6 +56,9 @@ class Command(BaseCommand): ...@@ -49,6 +56,9 @@ class Command(BaseCommand):
admin = get_user_model().objects.create_superuser("admin", password="password") admin = get_user_model().objects.create_superuser("admin", password="password")
admin.save() admin.save()
# Seed random generator to make this script deterministic
random.seed(options["seed"])
# Create sports # Create sports
sports_names = [ sports_names = [
"After Work Fitness", "After Work Fitness",
......
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