Python

FieldError: Cannot resolve keyword 'id' into field in Django project

FieldError: Cannot resolve keyword 'id' into field in Django project, someone asked me to explain?
I got this following error while running django web application "FieldError at /post/3/ Cannot resolve keyword 'id' into field. Choices are: description, id_category, image, name, status"FieldError

CODE:

def show_post(request, pk):
	post = get_object_or_404(Post,pk=pk)
	brand = Category.objects.get(id=post.category)
	return render(request, 'post.html', {'post':post, 'brand':brand})

SOLUTION:

If your model uses a different name for the primary key field, you should use that name instead. For above code, I used id=post.category but primary key field is id_category. so I changed it.

brand = Category.objects.get(id_category=post.category)

VIDEO GUIDE:

Post your comments / questions