Created
September 19, 2022 18:54
-
-
Save JorgeMichelena/b76c1a0baa30a526113f10b7b0189e0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
targets = Target.objects.annotate( | |
has_matches=Case( | |
When( | |
Q(matches_1__isnull=False) | Q(matches_2__isnull=False), | |
then=Value(True) | |
), | |
default=Value(False), | |
output_field=models.BooleanField(), | |
) | |
).prefetch_related("matches_1", "matches_2").order_by("-has_matches") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment