Cookbooks#
Step-by-step guide to some different you might want to do with Pegasus.
Pegasus customers can request content be added to this page! Just get in touch via support.
Use the Django Admin UI#
Pegasus ships with a simple script to promote any user to a superuser who can access the Django admin.
After going through the sign up flow, to convert your newly-created user into an admin, run the following command, being sure to replace the email address with the one you used to sign up:
Docker:
docker compose exec web python ./manage.py promote_user_to_superuser yourname@example.com
Native:
python ./manage.py promote_user_to_superuser yourname@example.com
Now you should be able to access the django admin at http://localhost:8000/admin
Migrating to auto-formatted code#
As of February, 2023 all Pegasus projects have the option to auto-format your Python code.
To migrate a project from non-formatted to formatted code, you can go through the following steps:
First, do a full Pegasus upgrade to the version you want to update to, as described here. Do not check the “autoformat” checkbox yet.
Next, run the formatting tools on your project’s
main
branch:Install black and isort:
pip install black isort
Run black:
black --extend-exclude migrations --line-length 120 .
Run isort:
isort -l 120 --profile black .
Commit the result:
git add .
git commit -m "apply formatting changes"
Finally, check the “autoformat” box on your Pegasus project, and do another upgrade according to the same process.
Delete Pegasus Examples#
On versions 2023.2 and later, you can remove the Pegasus examples by updating your build configuration and re-downloading (or upgrading) your codebase.
For earlier versions you can use the following instructions:
Clean the back-end code#
In
settings.py
, removePEGASUS_APPS
and the reference inINSTALLED_APPS
.In your root
urls.py
, remove the lines containinginclude('pegasus.apps.examples.urls')
andinclude('pegasus.apps.employees.urls')
.Delete the entire top-level
pegasus/
directory.Delete the entire
templates/pegasus/
directory.
Clean the front-end code#
In
webpack.config.js
, delete the'react-object-lifecycle'
,vue-object-lifecycle
and'pegasus'
entries frommodule.exports
.Delete the
assets/javascript/pegasus/
folder.Delete
assets/javascript/api-client/apis/PegasusApi.ts
and remove it fromassets/javascript/api-client/apis/index.ts
Delete
static/js/react-object-lifecycle-bundle.js
,static/js/vue-object-lifecycle-bundle.js
andstatic/js/pegasus-bundle.js
Delete Stripe Code#
If you aren’t using Stripe you can remove the code and dependencies by doing the following steps.
Note that this requires starting from a fresh database, or manually manipulating your migrations.
In
settings.py
removedjstripe
fromTHIRD_PARTY_APPS
In
settings.py
removeSTRIPE_
andDJSTRIPE_
settingsDelete
apps/utils/decorators.py
Delete
templates/stripe
directoryDelete the
@import "stripe.sass"
line fromassets/styles/app/_all.sass
Delete
assets/styles/app/stripe.sass
If you have not removed the examples using the method above, you also need to delete the payments example. This can be done with the following steps:
Delete the paths starting with
/payments/
frompegasus/apps/examples/urls.py
.Delete references to
Payment
frompegasus/apps/examples/admin.py
.In
pegasus/apps/examples/views/__init__.py
delete linefrom .payments import *
Delete
pegasus/apps/examples/views/payments.py
.In
pegasus/apps/examples/models/__init__.py
delete linefrom .payments import Payment
Delete
pegasus/apps/examples/models/payments.py
.Delete the relevant sections of
templates/pegasus/examples/examples_home.html
andtemplates/pegasus/examples/components/examples_nav.html
Delete the
templates/pegasus/examples/payments/
folder.In
assets/javascript/app.js
removeexport { Payments } from './Payments';
line.Delete
assets/javascript/payments.js
.Run
./manage.py makemigrations
and./manage.py migrate
Finally, remove the library dependencies:
In
requirements/requirement.in
andrequirements/requirement.txt
removestripe
anddj-stripe
lines.Run
pip-sync
Using the Payments example#
To make the Payments example a part of your own application, see this page.