models.py
def productFile(instance, request, filename):
old_name = str(filename)
new_name = "http://" + str(request.get_host()) + "/"+ str(instance.id)+".png"
renamed_image = os.rename(old_name, new_name)
return 'profile/'.join( [renamed_image] )
class User(models.Model):
mobile = models.CharField(max_length=20)
otp = models.CharField(max_length=6)
name = models.CharField(max_length=200)
username = models.CharField(max_length=200)
profile_dp = models.ImageField(upload_to = productFile ,null=True, blank=True)
profile_url = models.CharField(max_length=200)
settings.py
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICFILES_DIRS = [BASE_DIR / 'static']
MEDIA_URL = '/images/'
MEDIA_ROOT = BASE_DIR /'static/images'
Required Output
When i upload image in profile_dp the name image name should change into this format("http://" + str(request.get_host()) + "/"+ str(instance.id)+".png"
)
Error i am getting
productFile()
missing 1 required positional argument: 'filename'