Last active
January 27, 2018 14:10
-
-
Save bencleary/b6cf31b26a70c0b45ca367ba9782bf2d to your computer and use it in GitHub Desktop.
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
| class Csv(View): | |
| def get(self, request): | |
| sales = Sales.objects.all() | |
| headers = [(h.column) for h in Sales._meta.get_fields()] | |
| csv_array = Generate(request).csv_file(headers=headers, data=sales) | |
| if os.path.exists(csv_array[1]): | |
| with open(csv_array[1], 'r') as csv: | |
| response = HttpResponse(csv.read(), content_type="text/csv") | |
| response["Content-Disposition"] = f'attachment; filename={csv_array[0]}' | |
| return response | |
| else: | |
| return HttpResponse("File Does Not Exist") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment