I made a model which has an image field and it is allowed to be blank. How can I have a default image for the model when no image is set for it?
class Product(models.Model):
picture = models.ImageField(blank=True)
CodePudding user response:
You specify a default=…
value [Django-doc]:
class Product(models.Model):
picture = models.ImageField(blank=True, default='path/to/image.png')
the path is relative to the MEDIA_ROOT
setting [Django-doc].
CodePudding user response:
Do this:
class Product(models.Model):
picture = models.ImageField(blank=True,default="Add image url which is you want")