Модульный Telegram-бот с возможностью редактирования прав доступа, как пользователям, так и группам пользователей
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

49 lines
1.7 KiB

import requests
from django.http import HttpResponseRedirect
from django.utils.html import format_html
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from adminpanel.settings import g_telegram_bot_api_token
from .models import Orders
from django.contrib import admin, messages
from django.urls import reverse
class OrdersAdmin(admin.ModelAdmin):
list_display = ('orderName', 'orderCreateDateTime', 'show_orderPhoto', 'show_orderPhotoPay',)
actions =['change_value_and_redirect', ]
readonly_fields = ['orderPhoto', 'orderPhotoPay']
def show_orderPhoto(self, obj):
if obj.orderPhoto and obj.orderPhoto.url:
return format_html('<img src="{}" width="100" height="100" />', obj.orderPhoto.url)
return "-"
show_orderPhoto.short_description = 'Фото заказа'
def show_orderPhotoPay(self, obj):
if obj.orderPhotoPay and obj.orderPhotoPay.url:
return format_html('<img src="{}" width="100" height="100" />', obj.orderPhotoPay.url)
return "-"
show_orderPhotoPay.short_description = 'Фото чека'
def change_value_and_redirect(orders, request, queryset):
selected_objects = request.POST.getlist(ACTION_CHECKBOX_NAME)
if len(selected_objects) != 1:
messages.error(request, "Выберите только один объект")
return
selected_user_id = int(selected_objects[0])
obj = queryset.get(orderID=selected_user_id)
user_id = obj.userID
url = reverse('send_telegram_message', kwargs={'chat_id': user_id})
return HttpResponseRedirect(url)
change_value_and_redirect.short_description = 'Отправка сообщения'
admin.site.register(Orders, OrdersAdmin)