bulk_create给出意想不到的输出,这里有什么问题...... ????
class User(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
class MessagePost(models.Model):
send_to = models.ForeignKey(User)
media_def = models.TextField(blank=True)
message = models.TextField()
#userList fetched from db
userList = [User(first_name='a',last_name='b'),User(first_name='x',last_name='y')]
MessagePost.objects.bulk_create([MessagePost(send_to=u , media_def='media/images/1.png' , message='hai everyone') for u in userList ])
在使用bulk_create
时,它会出现以下错误的 输出 :
TypeError : expected string or buffer