I'm developing an e-commerce. Currently, i want to prevent the user from having access to Product DetailView of expired products. I can do this using UserPassesTestMixin, but as I'm not testing any userType, i don't know if it's the best way.
models.py
class ProdutosDetail(UserPassesTestMixin, DetailView):
model = Produto
template_name = "produto/produto_detail.html"
context_object_name = "product"
def test_func(self):
try:
assert self.get_object().expiration_date > date.today()
except AssertionError:
return False
else:
return True