Advertisement
Roman_Sarnov

Untitled

Jun 16th, 2020
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. images_dir = '/home/roman/Рабочий стол/images'
  2.  
  3. products =list( Product.objects.all())
  4.  
  5. categories =list(Category.objects.all())
  6. images_list = []
  7.  
  8. for address, dirs, files in folder:
  9. for file in files:
  10. images_list.append(address+'/'+file)
  11.  
  12.  
  13. for product in products:
  14. ...: initial = ProductImage.objects.create(product=random.choice(products))
  15. ...: file = random.choice(images_list)
  16. ...: initial.image.save(os.path.basename(file), File(open(file, 'rb')))
  17. ...: initial.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement