Reputation: 349
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)
Upvotes: 1
Views: 554
Reputation: 1970
Do this:
class Product(models.Model):
picture = models.ImageField(blank=True,default="Add image url which is you want")
Upvotes: 1
Reputation: 476574
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].
Upvotes: 2