Created
September 2, 2016 20:44
-
-
Save rg3915/6b8f748f467e39a009fcc35b04256cee to your computer and use it in GitHub Desktop.
Export data with django-excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' Exporta planilhas em Excel ''' | |
from datetime import datetime | |
import django_excel as excel | |
from django.http import HttpResponseBadRequest | |
from .models import Person | |
MDATA = datetime.now().strftime('%Y-%m-%d') | |
def export_data_person(request, atype): | |
if atype == "sheet": | |
return excel.make_response_from_a_table( | |
Person, 'xls', file_name="contatos") | |
elif atype == "custom": | |
query_sets = Person.objects.all() | |
column_names = ['id', 'name', 'email'] | |
return excel.make_response_from_query_sets( | |
query_sets, | |
column_names, | |
'xls', | |
file_name="contatos-" + MDATA | |
) | |
else: | |
return HttpResponseBadRequest( | |
"Bad request. please put one of these " + | |
"in your url suffix: sheet, book or custom") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment