Skip to content

Instantly share code, notes, and snippets.

@edigiacomo
Created November 21, 2014 07:44
Show Gist options
  • Select an option

  • Save edigiacomo/fdc5faef6cb0d06a3fe9 to your computer and use it in GitHub Desktop.

Select an option

Save edigiacomo/fdc5faef6cb0d06a3fe9 to your computer and use it in GitHub Desktop.
Automatic admin creation after `migrate` command in Django
from django.dispatch import receiver
from django.db import models
from django.contrib.auth.models import User
@receiver(models.signals.post_migrate)
def create_superuser(sender, **kwargs):
if not User.objects.filter(username='admin').first():
User.objects.create_superuser('admin', 'admin@localhost', 'admin')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment