Уведомления

Группа в Telegram: @pythonsu

#1 Дек. 26, 2018 22:19:02

SergeyKa777
Зарегистрирован: 2018-12-26
Сообщения: 1
Репутация: +  0  -
Профиль   Отправить e-mail  

Обработка POST запроса

Подскажите как можно из POST уведомления яндекс мани вытащить поле суммы и прибавить его к полю в базе данных models.py ? вот что у меня получилось но что то ни чего не получается .

@csrf_exempt
def http_notification(request):
response = HttpResponse(status=404)
if request.method == 'POST':
line_notification_options = '%s&%s&%s&%s&%s&%s&%s&%s&%s' % (
request.POST['notification_type'], request.POST['operation_id'], request.POST['amount'],
request.POST['currency'], request.POST['datetime'], request.POST['sender'], request.POST['codepro'],
settings.YANDEX_MONEY_SECRET_WORD, request.POST['label'])
if request.POST['sha1_hash'] == hashlib.sha1(line_notification_options.encode()).hexdigest():
YadTransaction.objects.create(
notification_type=request.POST['notification_type'],
currency=int(request.POST['currency']),
operation_id=request.POST['operation_id'],
amount=request.POST['amount'],
withdraw_amount=request.POST['withdraw_amount'] if 'withdraw_amount' in request.POST else 0,
datetime_transfer=dateutil.parser.parse(request.POST['datetime']),
sender=request.POST['sender'],
codepro=False if request.POST['codepro'] == 'false' else True,
label=request.POST['label'],
test_notification=True if 'test_notification' in request.POST else False,
)
lab = request.POST['label']
aaa = request.POST.get('withdraw_amount')
moss = Money.objects.get(moneyname=lab)
moss.moneyvalue += aaa
moss.save()
response = HttpResponse(status=200)

Models.py
....
withdraw_amount = models.DecimalField('Сумма, которая списана со счета отправителя', max_digits=12, decimal_places=2, null=True, blank=True)
.......

class Money(models.Model):
moneyname = models.CharField(max_length=120)
moneyvalue = models.DecimalField(decimal_places=2 ,max_digits=20)

Отредактировано SergeyKa777 (Дек. 26, 2018 22:19:41)

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version