update: create unidade and tag default elements
This commit is contained in:
parent
c602d0bf8d
commit
6b0bcdf723
1 changed files with 21 additions and 1 deletions
|
|
@ -2,7 +2,7 @@ from decouple import config
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from form_user.apps.contas.models import CustomUser
|
from form_user.apps.contas.models import CustomUser, TagUnidade, Unidade
|
||||||
|
|
||||||
|
|
||||||
class AppException(Exception, BaseCommand):
|
class AppException(Exception, BaseCommand):
|
||||||
|
|
@ -31,3 +31,23 @@ class Command(BaseCommand):
|
||||||
self.stdout.write(self.style.SUCCESS(_("Superuser created!")))
|
self.stdout.write(self.style.SUCCESS(_("Superuser created!")))
|
||||||
else:
|
else:
|
||||||
self.stdout.write(self.style.NOTICE(_("Superuser already exists!")))
|
self.stdout.write(self.style.NOTICE(_("Superuser already exists!")))
|
||||||
|
|
||||||
|
if not TagUnidade.objects.count():
|
||||||
|
self.create_tag_unidade(model=TagUnidade, el_list=["primeira", "segunda"])
|
||||||
|
else:
|
||||||
|
self.stdout.write(self.style.NOTICE(_("TagUnidade already exists!")))
|
||||||
|
|
||||||
|
if not Unidade.objects.count():
|
||||||
|
self.create_tag_unidade(model=Unidade, el_list=["qualquer", "coisa"])
|
||||||
|
else:
|
||||||
|
self.stdout.write(self.style.NOTICE(_("Unidade already exists!")))
|
||||||
|
|
||||||
|
def create_tag_unidade(self, model, el_list):
|
||||||
|
tags_uni = []
|
||||||
|
|
||||||
|
for el in el_list:
|
||||||
|
tags_uni.append(model(nome=el))
|
||||||
|
|
||||||
|
created_element = model.objects.bulk_create(tags_uni)
|
||||||
|
if created_element:
|
||||||
|
self.stdout.write(self.style.SUCCESS(f"{model.__name__} created!"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue