"""
Fix notifications with template code in message field
Run: python manage.py shell < fix_notification_messages.py
"""

from custom_admin.models import AdminNotification

# Delete notifications with template code in message
bad_notifications = AdminNotification.objects.filter(message__contains='{{')
count = bad_notifications.count()

if count > 0:
    print(f"Found {count} notifications with template code in message")
    bad_notifications.delete()
    print(f"✅ Deleted {count} bad notifications")
else:
    print("No bad notifications found")

# Also check title field
bad_titles = AdminNotification.objects.filter(title__contains='{{')
count2 = bad_titles.count()

if count2 > 0:
    print(f"Found {count2} notifications with template code in title")
    bad_titles.delete()
    print(f"✅ Deleted {count2} bad notifications")

print(f"\nRemaining notifications: {AdminNotification.objects.count()}")
