我正在运行批处理保存过程,但是我的post_save函数似乎没有针对每个对象运行?任何人都可以阻止任何问题吗?
保存功能
objs = [
Message(
recipient_number=e.mobile,
content=content,
sender=e.contact_owner,
billee=user,
sender_name=sender,
gateway=gateway,
)
for e in query
]
# Send messages to DB
Message.objects.bulk_create(objs)
models.py
@receiver(post_save, sender=Message)
def my_post_save_handler(sender, instance, **kwargs):
"""
Post Save Signal.
Sent at the end of the save() method. Attached to 'Message'.
"""
print("=========================================")
print(instance.gateway)
instance.send(instance.gateway)
post_save.connect(my_post_save_handler, sender=Message)
答案 0 :(得分:1)
post_save
和bulk_create
之外, update
不会被解雇。