Browse Source

не отправялось сообщение пользователю, т.к. токен брался из неправильно места #5

Anton 1 year ago
parent
commit
f1ce64061e
  1. 1
      adminpanelapp/admin.py
  2. 3
      adminpanelapp/models.py
  3. 4
      adminpanelapp/views.py

1
adminpanelapp/admin.py

@ -14,6 +14,7 @@ class OrdersAdmin(admin.ModelAdmin):
actions =['send_message']
exclude = ['orderAccess', 'userID', 'orderPhoto', 'orderPhotoPay']
def show_photo(self, obj):
html = obj.get_photo_html()
return mark_safe(html)

3
adminpanelapp/models.py

@ -14,7 +14,7 @@ class Orders(models.Model):
orderName = models.CharField(max_length=100, verbose_name='наименование', null=True)
orderDesc = models.TextField(verbose_name='описание', null=True)
orderPhoto = models.ImageField(verbose_name='фото', null=True)
orderPhotoPay = models.ImageField(upload_to='photo/', verbose_name='чек')
orderPhotoPay = models.ImageField(verbose_name='чек')
orderAddress = models.CharField(max_length=100, verbose_name='адрес доставки', blank=True, null=True)
orderAccess = models.CharField(max_length=100, verbose_name='доступ', blank=True, null=True)
orderCreateDateTime = models.DateTimeField(auto_now_add=True, null=True, verbose_name='дата и время создания')
@ -135,6 +135,7 @@ class Orders(models.Model):
"""
return html
class Meta:
verbose_name_plural = 'Заказы'

4
adminpanelapp/views.py

@ -3,14 +3,14 @@ from django.http import HttpResponseRedirect
import requests
from django.urls import reverse
from django.shortcuts import render
from bot_sys.config import g_telegram_bot_api_token
from bot_sys.config import GetTelegramBotApiToken
def send_telegram_message(request, chat_id):
if request.method == 'POST':
message = request.POST.get('message')
bot_token = g_telegram_bot_api_token
bot_token = GetTelegramBotApiToken()
url = f'https://api.telegram.org/bot{bot_token}/sendMessage?text={message}&chat_id={chat_id}'
response = requests.get(url)

Loading…
Cancel
Save