Change profile photo filename

This commit is contained in:
Keannu Bernasol 2023-07-15 00:01:51 +08:00
parent 447b034d38
commit fd08e3c58a

View file

@ -20,11 +20,9 @@ def validate_student_id(value):
class CustomUser(AbstractUser):
def _get_upload_to(instance, filename):
base_filename, file_extension = os.path.splitext(filename)
# Convert filename to a slug format
cleaned_filename = slugify(base_filename)
# Get the student ID number
student_id = str(instance.student_id_number)
new_filename = f"{student_id}_{cleaned_filename}{file_extension}"
new_filename = f"{student_id}_{file_extension}"
return os.path.join('avatars', new_filename)
first_name = models.CharField(max_length=100)