From 6f1c8cd8ff504123b63451f683f7279c0e5700e4 Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Fri, 10 Jul 2026 12:09:31 +0100 Subject: [PATCH] we can delete the message from telegram from the webui now --- .../apps/telegram_communication/admin.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/django_code/apps/telegram_communication/admin.py b/django_code/apps/telegram_communication/admin.py index 208c31d..be65569 100644 --- a/django_code/apps/telegram_communication/admin.py +++ b/django_code/apps/telegram_communication/admin.py @@ -1,8 +1,26 @@ from django.contrib import admin from import_export.admin import ImportExportModelAdmin from .models import TelegramData +from .utils import telegramUtils + +@admin.action(description="Clear all expired messages") +def messages_cleaning(modeladmin, request, queryset): + telegram = telegramUtils() + telegram.clear_expired_messages() # Register your models here. @admin.register(TelegramData) class JobAdmin(ImportExportModelAdmin): list_display = ('message_id','chat_id','description','creation_date','expiration_date') + actions = [messages_cleaning] + + def delete_queryset(self, request, queryset): + """Given a queryset, delete it from the database.""" + print("here") + telegram = telegramUtils() + list_of_message_id = list(queryset.all().values_list('message_id',flat=True)) + telegram.delete_message(list_of_message_id) + #no queryset.delete() because it is specified in delete_message function already + + +