def snapshot_to_json(self):
now = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
## don't include trailing slash in path -- it's in fullpath
## server (change parent dir to fixtures, add that path to Django settings and just leave dated subdirectory)
path = '/home/ubuntu/mccelections/electionsproject/snapshots/%s' % (election_date_string)
filename = '%s' % (now)
fullpath = '%s/%s.json' % (path, filename)
snapshotresults = serializers.serialize('json', Result.objects.filter(election_date=election_date_string))
f = open(fullpath, 'w')
f.write(snapshotresults)
f.close()
评论列表
文章目录