Hi Daniele, nice to see you around ![]()
I would personally start with a set of hardcoded status level as doing it through a many-to-many of the form
class TestStatus(models.Model):
level = models.SmallIntegerField()
description = models.Text()
class Product(models.Model):
test_statuses = models.ManyToMany(TestStatus, related_name="product")
...
Will make it quite hard to efficiently determine what’s the maximum level met (which I assume is of interest in your dashboard) through for each product (assuming you will list them) through SQL as this thread exemplifies.
In other words, it’s quite hard to craft a proper and efficient query to annotate the maximum level met for all existing test statuses.
You need something to generate SQL alike to
SELECT
(
SELECT status
FROM test_status
LEFT JOIN product_test_statuses ON (
product_test_statuses.teststatus_id = test_status.id
AND product_test_statuses.product_id = product.id
)
GROUP BY status
HAVING bool_and(product_test_statuses.id IS NOT NULL)
ORDER BY status DESC
LIMIT 1
) max_met_status
FROM product