Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Backend
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
swp-unisport
team-warumkeinrust
Backend
Commits
67bb06ed
Commit
67bb06ed
authored
3 years ago
by
fu2662cw
Browse files
Options
Downloads
Patches
Plain Diff
Prompt for admin password in seed_db (instead of hardcoding)
parent
6932ce35
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+5
-3
5 additions, 3 deletions
README.md
unisportomat/quiz/management/commands/seed_db.py
+8
-3
8 additions, 3 deletions
unisportomat/quiz/management/commands/seed_db.py
unisportomat/quiz/tests.py
+1
-1
1 addition, 1 deletion
unisportomat/quiz/tests.py
with
14 additions
and
7 deletions
README.md
+
5
−
3
View file @
67bb06ed
...
...
@@ -74,13 +74,15 @@ If successful, you can now see the running server in your browser at `http://127
## Populate the database with test data
To populate the database with some test data run
```
python manage.py seed_db [-y] [--seed SEED]
python manage.py seed_db [-y] [--seed SEED]
[--no-superuser]
```
All the existing data from your database will be lost!
All the existing data from your database will be lost!
Per default a super user called "admin" will be created for development.
You will be prompted for a password.
Run
`python manage.py seed_db --help`
for more information.
## 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
[
localhost:8000/admin
](
localhost:8000/admin
)
.
If you seeded the database you can login with username: "admin" and password
: "password"
If you seeded the database you can login with username: "admin" and
the
password
you specified.
This diff is collapsed.
Click to expand it.
unisportomat/quiz/management/commands/seed_db.py
+
8
−
3
View file @
67bb06ed
...
...
@@ -6,7 +6,6 @@ You can call this by python manage.py seed_db
import
random
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
django.contrib.auth
import
get_user_model
from
django.core.management
import
call_command
from
django.core.management.base
import
BaseCommand
from
quiz.models
import
(
...
...
@@ -45,6 +44,11 @@ class Command(BaseCommand):
default
=
42
,
help
=
"
Optional seed for random generator. Defaults to 42
"
,
)
parser
.
add_argument
(
"
--no-superuser
"
,
action
=
"
store_true
"
,
help
=
"
No super user shall be created
"
,
)
def
handle
(
self
,
*
args
,
**
options
):
"""
Create some objects for all models
"""
...
...
@@ -53,8 +57,9 @@ class Command(BaseCommand):
call_command
(
"
flush
"
,
"
--no-input
"
if
options
[
"
yes
"
]
else
[])
# Create admin user for using django admin interface during development
admin
=
get_user_model
().
objects
.
create_superuser
(
"
admin
"
,
password
=
"
password
"
)
admin
.
save
()
if
not
options
[
"
no_superuser
"
]:
self
.
stdout
.
write
(
"
\n
Specify admin password for development:
"
)
call_command
(
"
createsuperuser
"
,
"
--username=admin
"
,
"
--email=
''"
)
# Seed random generator to make this script deterministic
random
.
seed
(
options
[
"
seed
"
])
...
...
This diff is collapsed.
Click to expand it.
unisportomat/quiz/tests.py
+
1
−
1
View file @
67bb06ed
...
...
@@ -266,7 +266,7 @@ class SeedingTest(TestCase):
"""
If seed_db is called then there exists a certain number of elements per model
"""
# call the seed command without asking for confirmation
call_command
(
"
seed_db
"
,
[
"
--yes
"
])
call_command
(
"
seed_db
"
,
[
"
--yes
"
,
"
--no-superuser
"
])
n_sports
=
5
n_criteria
=
5
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment