class ProductView(ListView):
model = Products
max_id = Products.objects.all().aggregate(max_id=max("id"))['max_id']
random_products = set()
if Products.objects.filter(draft=False).count() < 4:
raise Exception('Мало объектов для выборки')
while len(random_products) < 4:
pk = random.randint(1, max_id)
product = Category.objects.filter(pk=pk).first()
if product:
random_products.append(product)
template_name = "products/index.html"