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

26 lines
701 B
Python
Raw Normal View History

2024-09-17 15:28:14 +00:00
from django.core.management.base import BaseCommand
from user.models import Institution
2024-09-18 16:01:46 +00:00
from lot.models import LotTag
2024-09-17 15:28:14 +00:00
class Command(BaseCommand):
help = "Create a new Institution"
def add_arguments(self, parser):
parser.add_argument('name', type=str, help='institution')
def handle(self, *args, **kwargs):
2024-09-18 16:01:46 +00:00
self.institution = Institution.objects.create(name=kwargs['name'])
self.create_lot_tags()
def create_lot_tags(self):
tags = [
"Entrada",
"Salida",
"Temporal"
]
for tag in tags:
LotTag.objects.create(
name=tag,
owner=self.institution
)