import time from urllib.parse import quote import requests from django.db import models from bot_sys.config import GetTelegramBotApiToken class Orders(models.Model): orderID = models.AutoField(primary_key=True, verbose_name='id заказа') userID = models.CharField(max_length=100, verbose_name='id пользователя в tg', null=True) 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(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='дата и время создания') orderStatus = models.CharField(max_length=100, verbose_name='статус заказа', blank=True, null=True) def get_photo_html(self, width=100, height=100, large_width=400, large_height=400): file_id = self.orderPhoto token = GetTelegramBotApiToken() url = f"https://api.telegram.org/bot{token}/getFile?file_id={file_id}" response = requests.get(url) data = response.json() if data['ok']: file_path = data["result"]["file_path"] photo_url = f"https://api.telegram.org/file/bot{token}/{quote(file_path, safe='')}" html = f""" Увеличить фото """ return html def get_photopay_html(self, width=100, height=100, large_width=400, large_height=400): token = GetTelegramBotApiToken() file_id = self.orderPhotoPay url = f"https://api.telegram.org/bot{token}/getFile?file_id={file_id}" response = requests.get(url) data = response.json() if data['ok']: file_path = data["result"]["file_path"] photo_url = f"https://api.telegram.org/file/bot{token}/{quote(file_path, safe='')}" html = f""" Увеличить фото """ return html class Meta: verbose_name_plural = 'Заказы' managed = False db_table = 'orders'