提问人:Bobmaintain 提问时间:3/22/2023 最后编辑:Bobmaintain 更新时间:3/22/2023 访问量:42
使用 if-elif-else 语句在回调函数中增加这些喜欢和检查模型属性的最佳方法是什么?
What is the best way to increment these likes and checks model attributes in a callback function using an if-elif-else statement?
问:
我不想创建两个回调函数。我希望使用 if-elif-else 语句以有条件的方式执行此回调。
首先,代码会按原样运行吗?那么,如果没有,将 house.likes 和 house.checks 放在 if-else 或 if-elif-else 语句中的最佳方式是什么?
def callback(ch, method, properties, body):
print('Received in config')
id = json.loads(body)
print(id)
house = House.objects.get(id=id)
house.likes = house.likes + 1
house.save()
print('House likes increased!')
house.checks = house.checks + 1
house.save()
print('House checks increased!')
我还没有尝试重构它......仍在研究代码块。我不想破坏东西。
答: 暂无答案
评论