Django bulk_create function example

The second code in the question create a single object, because it pass a set with a Message object.

To create multiple objects, pass multiple Message objects to bulk_create. For example:

objs = [
    Message(
        recipient_number=e.mobile,
        content=batch.content,
        sender=e.contact_owner,
        billee=batch.user,
        sender_name=batch.sender_name
    )
    for e in q
]
msg = Message.objects.bulk_create(objs)

Leave a Comment