Created
March 15, 2016 15:37
-
-
Save elvikito/4fd5807ca7c49256857e 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 FileDownloadView(APIView): | |
| permission_classes = (IsAuthenticated,) | |
| def get(self, request, pk): | |
| # trade = Trade.objects.filter(account__portfolio=pk).values() | |
| trade = Trade.objects.filter(account__portfolio=pk) | |
| for t in trade: | |
| with open('names.csv', 'w') as csvfile: | |
| fieldnames = ['fake', 'confidence', 'counter_quantity', | |
| 'account_id', 'external_identifier', 'fees_misc', | |
| 'commissions', 'price', 'tradefile_id', | |
| 'counter_security_id', 'ts', 'drip', 'tag', | |
| 'trade_time', 'trade_date', 'security_id', | |
| 'counter_account_id', 'type', 'id', 'trade_source', | |
| 'quantity'] | |
| writer = csv.DictWriter(csvfile, fieldnames=fieldnames) | |
| writer.writeheader() | |
| writer.writerow({'fake': t.fake, 'confidence': t.confidence, | |
| 'counter_quantity': t.counter_quantity, | |
| 'account_id': t.account_id, | |
| 'external_identifier': t.external_identifier, | |
| 'fees_misc': t.fees_misc, | |
| 'commissions': t.commissions, | |
| 'price': t.price, | |
| 'tradefile_id': t.tradefile_id, | |
| 'counter_security_id': t.counter_security_id, | |
| 'ts': t.ts, 'drip': t.drip, 'tag': t.tag, | |
| 'trade_time': t.trade_time, | |
| 'trade_date': t.trade_date, | |
| 'security_id': t.security_id, | |
| 'counter_account_id': t.counter_account_id, | |
| 'type': t.type, 'id': t.id, | |
| 'trade_source':t.trade_source, | |
| 'quantity': t.quantity | |
| }) | |
| # writer.close() | |
| open('names.csv', 'rb').read() | |
| message = {'mesage' : 'test'} | |
| return Response(message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment