使用Django获取发送到Telegram Bot的图像

时间:2018-02-12 15:12:39

标签: python django telegram telegram-bot

我想将用户发送的图像提取到电报机器人 并将此图像保存在数据库中,只是想在URL / admin中看到此图像 我的models.py

public static TAttribute[] GetAllAttributes<TAttribute>(MemberInfo member, bool inherits)
    where TAttribute : Attribute
{
    Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(member, "member");

    List<TAttribute> attributes = new List<TAttribute>();

    if (member.DeclaringType != null)
    {
        attributes.AddRange(GetAttributes<TAttribute>(member.DeclaringType.GetTypeInfo(), inherits));

        MethodInfo methodInfo = member as MethodInfo;
        if (methodInfo != null)
        {
            PropertyInfo prop = GetPropertyFromMethod(methodInfo);
            if (prop != null)
            {
                attributes.AddRange(GetAttributes<TAttribute>(prop, inherits));
            }
        }
    }
    attributes.AddRange(GetAttributes<TAttribute>(member, inherits));
    return attributes.ToArray();
}

我的观点.py from django.db import models # Create your models here. class BotUser(models.Model): chat_id = models.BigIntegerField() step = models.CharField(max_length=50, null=True, blank=True) username = models.CharField(max_length=120, null=True, blank=True) fio = models.CharField(max_length=120, null=True, blank=True) city = models.CharField(max_length=120, null=True, blank=True) date_wedding = models.DateField(blank=True, null=True) photo = models.ImageField(null=True, blank=True) date_in = models.DateTimeField(auto_now_add=True, auto_now=False, null=True, blank=True) def __str__(self): return 'user_id = ' + str(self.id) + ' chat_id = ' + str(self.chat_id) + ' ' + self.fio + ' ' + self.username class Meta: verbose_name = 'Telegram User' verbose_name_plural = 'Telegram User' 然后

import telebot

我得到错误看起来像分配前引用的局部变量'chat_id'。 我认为user.step =='input_date'中的错误。 非常感谢你。

0 个答案:

没有答案