<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def with_active_flag(self):
 """ A query set where each result is annotated with an 'is_active' field that indicates if it's the most recent entry for that combination of keys. """

        if self.model.KEY_FIELDS:
            return self.get_queryset().annotate(
                is_active=models.ExpressionWrapper(
                    models.Q(pk__in=self._current_ids_subquery()),
                    output_field=models.IntegerField(),
                )
            )
        return self.get_queryset().annotate(
            is_active=models.ExpressionWrapper(
                models.Q(pk=self.model.current().pk),
                output_field=models.IntegerField(),
            )
        )