python - Django object has no attribute -


i have bulk update. each message created need call .send(gateway) have tried:

  objs = [                                        message(                                        recipient_number=e.mobile,                  content=content,                            sender=e.contact_owner,                     billee=user,                                sender_name=sender                      ).send(gateway)                                           e in query                           ]                                           # send messages db                       message.objects.bulk_create(objs)     

i error:

task request process id 3ab72d3c-5fd8-4b7d-8cc5-e0400455334f raised exception: 'attributeerror("\'nonetype\' object has no attribute \'pk\'",)'

why?

you creating objs list calling send on each element of query. presumably, send not return , list of none. try this:

objs = [] element in query:     message = message(**kwargs)     message.send(gateway)     objs.append(message)  message.objects.bulk_create(objs) 

**kwargs placeholder parameters pass message. can use dictionary or pass parameters in original code.

as side note, list comprehensions indicated when want new list , not side effects (like sending message). here want both, for loop appropriate.