Jul-02-2018, 04:57 AM
Hi All,
I have implemented a functionality-upload image to S3 from Django2.0.6+Python3.6+MySql.
And this functionality is working fine.
Now I want to save the uploaded image url to 'image_url' field of a table- Brand in database.
My image uploading code (models.py) is as below-
I have implemented a functionality-upload image to S3 from Django2.0.6+Python3.6+MySql.
And this functionality is working fine.
Now I want to save the uploaded image url to 'image_url' field of a table- Brand in database.
My image uploading code (models.py) is as below-
class Brand(models.Model): name = models.CharField(max_length=60) description = models.TextField(blank=True, null=True) created_at = models.DateTimeField(auto_now_add=True, editable=False) updated_at = models.DateTimeField(auto_now=True) @property def logo(self): return get_logo(self.name, 'brand') class Meta: managed = False db_table = 'brand' def __str__(self): return self.name
def get_logo(logo_name, folder): logo_name_with_ext = '{}{}'.format(logo_name, '.png') logo_url = '{}/{}'.format(IMAGE_PATH, os.path.join(folder, logo_name_with_ext)) return mark_safe('<img src="{}" height="20" />'.format(logo_url))Can anyone please suggest me what changes should I make here?