-
-
Save Afeez1131/29b7be67ca22180f0451095bd454bad3 to your computer and use it in GitHub Desktop.
Export data with django-excel
This file contains hidden or 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