Django Tips

REPL driven development

In addition to working with Django admin for testing, you can also get REPL access to your Django environment:

$ python shell

and do things like test out how to access or filter a model, etc

Same with the db env:

$ python dbshell


See migations with showmigrations:

$ python showmigrations

Or create a migation:

$ python makemigration

Migrate with migrate, or roll back a migration by referencing the migration before it for the given section:

$ pythom migrate core 002_migation_to_rollback_to

A migration that involves additional processing such as a backfill can also be done. Create an empty migration and then use RunPython:

from django.db import migrations

def run_backfill(apps, schema_editor):
    MyModel = apps.get_model('core', 'MyModel')
    db_alias = schema_editor.connection.alias
    model = MyModel.objects.using(db_alias).get(...)

class Migration(migations.Migration):
    dependencies = [
        ('core', '003_backfill')

    operations = [


Serving production static files