I'm Inserting multiple images to database. I have saved the new Image name is Dictonary. But while inserting the data to table i'm getting ERROR : 'int' object is not subscriptable'
I have searched everywhere but couldn't find solution.
Here is below how Dictonary looks like
{
"0" = {
"blog_id" = "".
"blog_image_path" = "07-09-2018__17-54-152069weather.jpg".
"is_deleted" = 0
}.
"1" = {
"blog_id" = "".
"blog_image_path" = "07-09-2018__17-54-152069user.png".
"is_deleted" = 0
}.
"2" = {
"blog_id" = "".
"blog_image_path" = "07-09-2018__17-54-152069tick.png".
"is_deleted" = 0
}
}
Now while adding the DB
for image in blog_images_data:
blog_image_data = BlogImages(blog_id=int(blog_id), blog_image_path=image['blog_image_path'], is_deleted=int(image['is_deleted']))# I GET ERROR IN THIS LINE
blog_image_data.save()
I have even changed the datatype to INT but still error persists.
Below is the Model Details
class BlogImages(models.Model):
blog_image_id = models.AutoField(primary_key=True)
blog = models.ForeignKey(Blog, null=True, on_delete=models.CASCADE)
blog_image_path = models.TextField(null=True)
is_deleted = models.SmallIntegerField(default=0, editable=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
db_table = 'tbl_blog_images'
{ key: value }, not{ key = value }.imagein your code is just anint(for example42, so thenimage['blog_image_path']indeed makes no sense, you iterated over the keys.