Skip to content

Instantly share code, notes, and snippets.

@elvikito
Created March 15, 2016 15:37
Show Gist options
  • Select an option

  • Save elvikito/4fd5807ca7c49256857e to your computer and use it in GitHub Desktop.

Select an option

Save elvikito/4fd5807ca7c49256857e to your computer and use it in GitHub Desktop.
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