from django.db.models import Max, Case, When, IntegerField
qs = MyObject.objects.all()
a_priority = Case(When(a='A', then=1), When(a='S', then=2), When(a='Q',
    then=3), output_field=IntegerField())
qs = qs.values('b', 'c').annotate(max_a_priority=Max(a_priority))
Maximum of an annotation after a group by