1

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')

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.