From 3c06baa684139c16c9c76e96e16b61b280c2b35c Mon Sep 17 00:00:00 2001 From: Jonathan Math Date: Fri, 3 Jul 2020 02:11:02 -0400 Subject: [PATCH] Update management commands to assist with development --- .../management/commands/remove_last_user.py | 15 +++++++++++++++ apps/profile/management/commands/startup.py | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 apps/profile/management/commands/remove_last_user.py diff --git a/apps/profile/management/commands/remove_last_user.py b/apps/profile/management/commands/remove_last_user.py new file mode 100644 index 000000000..3e6a07883 --- /dev/null +++ b/apps/profile/management/commands/remove_last_user.py @@ -0,0 +1,15 @@ +# this command helps with development. It removes the last created user +# in case there was a problem with creating a user and profile manually. +from django.conf import settings +from django.contrib.auth.models import User +from django.core.management.base import BaseCommand + +from apps.profile.models import Profile +class Command(BaseCommand): + + def handle(self, *args, **options): + user = User.objects.last() + profile = Profile.objects.get(user=user) + profile.delete() + user.delete() + print("User and profile for user {0} deleted".format(user)) \ No newline at end of file diff --git a/apps/profile/management/commands/startup.py b/apps/profile/management/commands/startup.py index d31966d0a..4ff57f6ee 100644 --- a/apps/profile/management/commands/startup.py +++ b/apps/profile/management/commands/startup.py @@ -20,4 +20,3 @@ class Command(BaseCommand): print("User {0} created".format(username)) _create(settings.HOMEPAGE_USERNAME) - _create('popular')