I keep getting the following error:
'function' object has no attribute 'objects' for Like.
It does exist on this view and I can’t see why the error occurs. Any help?
def Like(request, username, id):
""" User likes a project """
#message.success(request, "You've liked this project!")
# Get the username
user = get_object_or_404(User, username=username)
# Get the project
project = get_object_or_404(Project, id=id)
# Create the like
like = Like.objects.create(user=user.id, project=project.id)
return render_to_response('projects/liked.html')
You’ve called your view function the same as your model, so the view has overwritten the name “Like” in the current namespace.
If you stuck to PEP8 naming conventions, you’d always give your functions lowercase names, so this wouldn’t happen.