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

32 lines
828 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
2025-02-17 12:05:41 +00:00
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):
2025-02-17 12:05:41 +00:00
LotTag.objects.create(
inbox=True,
name="Inbox",
owner=self.institution
)
2024-09-18 16:01:46 +00:00
tags = [
"Entrada",
"Salida",
"Temporal"
]
for tag in tags:
LotTag.objects.create(
name=tag,
owner=self.institution
)