18 - Working with Expression Wrappers: Filtering None?

In section 18 - Working with Expression Wrappers, I feel like there is something missing with the given exercises. For clarity, I am using postgres as my database.

On the last problem, “Top 5 best-selling products and their total sales”, the query returns a bunch of None values. This is something that we would want to filter out, so wouldn’t we want to add something like a .exclude(total_sales__isnull=True) before the order_by and slicing?

Please let me know if this is a difference due to me using a postgres database.


queryset = Product.objects.annotate(total_quantity=Sum(‘orderitem__quantity’)).filter(total_quantity__isnull=False).order_by(’-total_quantity’)[:5]

This is what I have coded, but it only gives the top 5 best-selling products based on the quantity.

But I have a few questions regarding the logic applied in the solution provided by Mosh. He has deduced the best-selling products based on the sales value and not the total quantity.