Is it possible to delete last n records of a django model in one/minimum database query?

Solution 1:

You can use the primary keys in the queryset to filter with pk__in=…:

Task.objects.filter(
    pk__in=Task.objects.filter(type='Active').order_by('-id').values('pk')[:10]
).delete()