Skip to content

Instantly share code, notes, and snippets.

@glauesppen
Created September 6, 2017 14:34
Show Gist options
  • Save glauesppen/983037e53e68a02cdb9d1f8ff9246e7b to your computer and use it in GitHub Desktop.
Save glauesppen/983037e53e68a02cdb9d1f8ff9246e7b to your computer and use it in GitHub Desktop.
Using pandas to report
import pandas as pd
from leilao.models import Lance
lista = ['PTN07-17A-SUCATAS', 'PTN07-17B-SUCATAS', 'PTN07-17C-SUCATAS','PTN07-17D-SUCATAS']
queryset = (
Lance.objects
.filter(lote__leilao__nome__in=lista)
.values('lote__leilao__nome', 'user__userprofile__nome', 'user__email', 'user__userprofile__telefone1', 'user__userprofile__telefone2')
.distinct()
)
dados = pd.DataFrame(list(queryset))
dados = dados.drop_duplicates()
dados = dados.rename(columns={
'lote__leilao__nome': 'Leilao',
'user__userprofile__nome': 'Nome',
'user__email': 'Email',
'user__userprofile__telefone1': 'Telefone1',
'user__userprofile__telefone2': 'Telefone2',
})
dados.to_excel('dados.xls')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment