-
Notifications
You must be signed in to change notification settings - Fork 9
Plain Language Django Guide & Irreverent FAQ
-
What's the deal with
manage.py? And we also talk aboutdjango-admin, what's that?Manage.pyanddjango-adminare two different ways of running a bunch of different commands.Manage.pyis easier, and you can use it like:docker-compose run app python manage.py <command> [options]django-admina command line tool, not to be confused with the tenants2 admin page, which is only available to logged-in superusers (i.e. our staff). -
COOL MANAGE.PY COMMANDS
-
Dbshell: this lets you run arbitrary SQL commands on your local database. Helpful for testing database migrations. e.g.$ docker-compose run app python manage.py dbshell justfix=# select lease_type, user_id from onboarding_onboardinginfo; lease_type | user_id --------------------------------- MARKET_RATE | 1 RENT_STABILIZED | 2 (2 rows) -
Makemessages: this is used bydcra node localebuilder.jsfor updating translated strings in all themessages.pofiles -
Makemigrations: This creates all the new db migrations that result from changes you’ve made to django models and stuff -
Migrate: Apply all unapplied migrations to your local db Like if you want to change all the users with housing type “old type” to housing type “new type”, that’s a migration. -
Shell: Don’t confuse it withdbshell. This just opens a python interpreter -
TestWe only have 10 tests that django knows about. You probably wantdocker-compose run app pytest``docker-compose run app yarn test``` -
RunserverThis is whatdocker-compose upeventually runs under the hood to start the app.
-
-
What's the difference between apps and projects?
App nameisthe basename of the package containing your modules. We have lots of apps: onboarding, hpaction, issues, loc, norent, nycdb, nycha, nycx - some of them correspond to what we’d call an ‘app’ in normal parlance in terms of something users interact with but many don’t and are just package names. Just in case you weren’t confused enough, check the “projects vs apps” description here -
What's
settings.py?Settings.pyis what configures a bunch of stuff so when you run things likemanage.py dbshell, it knows what kind of db it is and whether to runmysqlorpostgresql, etc. I haven’t had to change this stuff much yet.