In my Django project I have Products
.
You can access products using this url pattern:
example.com/tshirt
or example.com/jacket
etc.
Moreover, you can view some other pages for those products, i.e.:
example.com/tshirt/details
or example.com/jacket/buy
My problem:
When I create a new product in my admin interface, the product is deactivated by default (I can activate it later). The reason is that when I create a new product I often don't have all necessary information yet (i.e. price). As long as a product is deactivated all URLs starting with example.com/this-one-product
should not be visible for the normal visitor (getting 404 error). Unfortunately, I don't know how to do that.
My goal is that it's visible for the super user or users from the staff. Because it makes sense that they can check that product and see how it looks like when it's rendered. But, as said, it should not be visible for the normal visitor of the webpage.
Now I could of course create if statements in all those views (and check if superuser or from staff), but that does not sound like a elegant solution. Because I would have to add those statements to many different views and that's against DRY and I just don't like this solution.
What would be perfect: A setting to deliver 404 error for all visitors of a product that is deactivated. How is that possible?