Are you trying to use an if statement and exist ()? I think it is easier.
def goal_display(request):
user = get_object_or_404(User, id=request.user.id)
if request.user != user:
return permission_denied(request)
if(Goal.objects.filter(user=user).lastest('created').exists()):
goal = Goal.objects.filter(user=user).latest('created')
return render_to_response('achieve/dashboard.html', {
"goal": goal
}, context_instance=RequestContext(request))
else:
return redirect('goal_add')
This may not be the most beautiful way, but I think it should work.
source
share