MoniMurray / bookworms-et-al

1 stars 1 forks source link

View Products by Author #20

Open MoniMurray opened 1 year ago

MoniMurray commented 1 year ago

As a site user I want to be able to view products by author so that I can select works by the same author

Acceptance Criteria

Tasks

MoniMurray commented 1 year ago

Author is a ForeignKey in the Product model, so has to be searched as an author object rather than as a string dataset. use get_object_or_404 for the author and then use a simple filter.

  1. You have a form which is providing a string to the view

  2. You have a view which is using the string to create a filter

  3. 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.

MoniMurray commented 1 year ago

I used Q(authornameicontains=query) in the end, to query the name field in the author model.