-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bc6060
commit 0cdf32b
Showing
2 changed files
with
19 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
from django.apps import AppConfig | ||
|
||
# Importe o arquivo signals.py | ||
from . import signals | ||
|
||
|
||
class FilmeConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'filme' | ||
|
||
def ready(self): | ||
from .models import Usuario | ||
import os | ||
|
||
email = os.getenv("EMAIL_ADMIN") | ||
senha = os.getenv("SENHA_ADMIN") | ||
|
||
usuarios = Usuario.objects.filter(email=email) | ||
if not usuarios: | ||
Usuario.objects.create_superuser( | ||
username="admin", email=email, password=senha, is_active=True, is_staff=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.db.models.signals import post_migrate | ||
from django.dispatch import receiver | ||
from .models import Usuario | ||
import os | ||
|
||
|
||
@receiver(post_migrate) | ||
def create_superuser(sender, **kwargs): | ||
if sender.name == 'filme': | ||
email = os.getenv("EMAIL_ADMIN") | ||
senha = os.getenv("SENHA_ADMIN") | ||
|
||
usuarios = Usuario.objects.filter(email=email) | ||
if not usuarios: | ||
Usuario.objects.create_superuser( | ||
username=email, email=email, password=senha, is_active=True, is_staff=True, is_superuser=True) |