devicehub-django/user/management/commands/add_user.py

38 lines
995 B
Python
Raw Normal View History

2024-07-01 10:19:02 +00:00
from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model
2024-07-18 15:21:22 +00:00
from lot.models import LotTag
2024-07-01 10:19:02 +00:00
User = get_user_model()
class Command(BaseCommand):
help = "Create a new user"
def add_arguments(self, parser):
parser.add_argument('email', type=str, help='email')
parser.add_argument('password', type=str, help='password')
def handle(self, *args, **kwargs):
email = kwargs['email']
password = kwargs['password']
self.create_user(email, password)
2024-07-18 15:21:22 +00:00
self.create_lot_tags()
2024-07-01 10:19:02 +00:00
def create_user(self, email, password):
2024-07-18 15:21:22 +00:00
self.u = User.objects.create(email=email, password=password)
self.u.set_password(password)
self.u.save()
def create_lot_tags(self):
tags = [
"Entrada",
"Salida",
"Temporal"
]
for tag in tags:
LotTag.objects.create(
name=tag,
owner=self.u
)