Skip to content

Plain Language Django Guide & Irreverent FAQ

Samara Trilling edited this page Aug 6, 2021 · 16 revisions

FAQ

  1. What's the deal with manage.py? And we also talk about django-admin, what's that?

    Manage.py and django-admin are two different ways of running a bunch of different commands. Manage.py is easier, and you can use it like:

    docker-compose run app python manage.py <command> [options]
    

    django-admin a command line tool, not to be confused with the tenants2 admin page, which is only available to logged-in superusers (i.e. our staff).

  2. 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 by dcra node localebuilder.js for updating translated strings in all the messages.po files

    • 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 with dbshell. This just opens a python interpreter

    • Test We only have 10 tests that django knows about. You probably want docker-compose run app pytest`` docker-compose run app yarn test```

    • Runserver This is what docker-compose up eventually runs under the hood to start the app.

  3. What's the difference between apps and projects?

    App name is the 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

  4. What's settings.py?

    Settings.py is what configures a bunch of stuff so when you run things like manage.py dbshell, it knows what kind of db it is and whether to run mysql or postgresql, etc. I haven’t had to change this stuff much yet.

Clone this wiki locally