model ProductFilter has products ManyToManyField. I need to get attribute to_export from product.filters of the highest priority (ProductFilter.priority field)
I figured out this
filters = ProductFilter.objects.filter(products__in=[OuterRef('pk')]).order_by('priority')
Product.objects.annotate(filter_to_export=Subquery(filters.values('to_export')[:1]))
But it raises
ValueError: This queryset contains a reference to an outer query and may only be used in a subquery.
Do you know why?