Answer the question
In order to leave comments, you need to log in
How to upload an image to an Imagefield?
models.py
class FinePhoto(models.Model):
partner = models.ForeignKey(Partner, on_delete=models.CASCADE)
fine = models.ForeignKey(Fine, on_delete=models.CASCADE)
image = models.ImageField(upload_to='fine_images', blank=True, null=True)
photo = FinePhoto(fine=fine, partner=partner)
photo.image = добавить фото из статика
photo.save()
Answer the question
In order to leave comments, you need to log in
You need not a static but a media folder. Set up media. And in ImageField you add upload_to="img/" where it is assumed that img is in media
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question