Open MoniMurray opened 1 year ago
Category_name is a ForeignKey in the Product model, so has to be searched as category object rather than as a string dataset. use get_object_or_404 for the category (like in author) and then use a simple filter.
The form in base.html is providing a string to the view
The view is using the string to create a filter
You filter the database by said filter and return the context to display.
Test using print statements throughout at each point of the all_products.
Currently blocked, will review later in development
Reviewed some YouTube videos to learn how to structure search functions. This was the most useful: https://www.youtube.com/watch?v=AGtae4L5BbI&pp=ygUec2VhcmNoIHByb2R1Y3RzIGZlYXR1cmUgZGphbmdv.
Q(category_namenameicontains=query) was what I used to query the foreignkey field of 'category_name' in Product model, and drill down into the Category model field 'name' to see if it contained the query value. Happily it works.
In Fixtures categories.json, ensure name attribute is one word only to enable filter to work in main_nav
As a site user I want to be able to view products by category so that I can group products by the category or genre that interests me
Acceptance Criteria
Tasks