Django: Get ImageField url in view
When configured correctly, use .url: item.image.url. Check the docs here.
When configured correctly, use .url: item.image.url. Check the docs here.
I found that the ImageField’s name is u”, so is there any better way to do it ? Actually, it looks like that’s exactly how this class evaluates bool(), so the better way is to just test its bool() by calling if p.avatar ImageFieldFile subclasses File, which defines: def __nonzero__(self): return bool(self.name) So the better … Read more
You can receive the pre_delete or post_delete signal (see @toto_tico’s comment below) and call the delete() method on the FileField object, thus (in models.py): class MyModel(models.Model): file = models.FileField() … # Receive the pre_delete signal and delete the file associated with the model instance. from django.db.models.signals import pre_delete from django.dispatch.dispatcher import receiver @receiver(pre_delete, sender=MyModel) def … Read more