Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ollieglass/4678134 to your computer and use it in GitHub Desktop.
Save ollieglass/4678134 to your computer and use it in GitHub Desktop.
AJAX helper function for storing credit card transaction categories, from my personal finance mini-hackathon http://ollieglass.com/2013/01/30/personal-finance-mini-hackathon
def transaction(request):
transaction_id = request.REQUEST.get('transactionId')
category_id = request.REQUEST.get('categoryId')
t = Transaction.objects.get(pk=transaction_id)
m = t.merchant
c = Category.objects.get(pk=category_id)
m.category = c
m.save()
data = {
'merchant': m.name,
'category': c.name
}
return HttpResponse(json.dumps(data), content_type="application/json")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment