Skip to content

Commit

Permalink
Fix queryset update with annotated order columns
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanw committed Jan 14, 2025
1 parent 0757bd2 commit 5a6970c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fragdenstaat_de/fds_donation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ def send_donor_optin_email(self, request, queryset):
send_donor_optin_email.short_description = _("Send opt-in mail")

def clear_duplicates(self, request, queryset):
queryset.update(duplicate=None)
# Clear order of queryset to avoid ordering on non-existing annotation columns
queryset.order_by().update(duplicate=None)
self.message_user(request, _("Duplicate flags cleared."))

clear_duplicates.short_description = _("Clear duplicate flag on donors")
Expand Down Expand Up @@ -340,13 +341,15 @@ def detect_duplicates(self, request, queryset):

@admin.action(description=_("Mark invalid addresses"))
def mark_invalid_addresses(self, request, queryset):
queryset.filter(
qs = queryset.filter(
Q(postcode="")
| Q(address="")
| Q(city="")
| Q(last_name="")
| ~(Q(postcode__regex=r"^\d{5}$") | ~Q(country="DE"))
).update(invalid=True)
)
# Clear order of queryset to avoid ordering on non-existing annotation columns
qs.order_by().update(invalid=True)

def merge_donors(self, request, queryset):
"""
Expand Down

0 comments on commit 5a6970c

Please sign in to comment.