Reputation: 105
Im calling an endpoint in my template:
var postdata = { 'csrfmiddlewaretoken': '{{ csrf_token }}' }
$.post("reconcile/" + transaction_id, postdata);
Here is the view:
def reconcile_transaction(request, slug, id):
society = get_object_or_404(Society, slug=slug)
try:
society.members.get(pk=request.user.id)
except society.DoesNotExist:
return HttpResponseRedirect('/')
account = society.account
transaction = Transaction.objects.filter(id=id)
print(transaction.get_stubbed_time)
I'm getting a 500 error at the print statement.
Any ideas?
Upvotes: 0
Views: 93
Reputation: 473893
filter()
returns a QuerySet (basically, a list of model instances). And, since there is no get_stubbed_time
attribute on a QuerySet
- you are getting AttributeError
while trying to get get_stubbed_time
attribute from a queryset. And, because of you are not running in the DEBUG mode - you are seeing 500.
You need to use get() instead:
transaction = Transaction.objects.get(id=id)
print(transaction.get_stubbed_time)
Also, keep DEBUG=True
in development - it helps a lot to quickly understand the root cause of errors. But, don't forget to turn it off in production.
Hope that helps.
Upvotes: 3