Skip to content

Instantly share code, notes, and snippets.

@CoutinhoElias
Last active December 8, 2018 02:08
Show Gist options
  • Save CoutinhoElias/0cda80d46b4c1fbe88ae420402e189ec to your computer and use it in GitHub Desktop.
Save CoutinhoElias/0cda80d46b4c1fbe88ae420402e189ec to your computer and use it in GitHub Desktop.
Populando modelo Person
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dccrecibo.settings")
django.setup()
#from django.utils.text import slugfy
from dccrecibo.core.models import Person
def populate(request):
#import ipdb; ipdb.set_trace()
PERSONS_ADD = [{'cpf_cnpj':'00.000.000/3875-09','name':'BANCO DO BRASIL S.A'},
{'cpf_cnpj':'00.000.320/6413-68','name':'JOSE CELIO GURGEL DE CASTRO'},
{'cpf_cnpj':'00.000.885/0001-29','name':'BRASAL BRASÍLIA SERVIÇOS AUTOMOTORES S/A'},
{'cpf_cnpj':'00.004.309/0001-50','name':'DF VEICULOS LTDA'},
{'cpf_cnpj':'00.025.131/0001-23','name':'RDA Com e Rep. e Imp. de Mat. Elet. S/A'},
{'cpf_cnpj':'00.025.131/0002-04','name':'RDA COM. REPRES. E IMPORT DE MATER. ELETR. LTDA'},
{'cpf_cnpj':'999.786.873-00','name':'ARIEL VICTOR OLIVEIRA DOS SANTOS'},
{'cpf_cnpj':'999.809.753-34','name':'NATALIA FEITOSA ARRAIS'},
{'cpf_cnpj':'999.887.553-68','name':'JESSICA LIA MARTINS SOUSA DA SILVA'},
{'cpf_cnpj':'999.912.840-87','name':'RAFAEL TONIAZZO'},
{'cpf_cnpj':'999.974.953-49','name':'GRAZIELA COSTA ARAUJO'}]
lista = []
for person in PERSONS_ADD:
obj = person['name']=PERSONS_ADD[1], person['cpf_cnpj']=PERSONS_ADD[0]
lista.append(obj)
print(lista)
Person.objects.bulk_create(lista)
@mazulo
Copy link

mazulo commented Dec 7, 2018

for person in PERSONS_ADD:
        obj = Person(**person)
        lista.append(obj)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment