I have a form where a user can update their profile. I want the user to choose from a drop down list of all the available profile pictures (a gallery of profile pictures from the ProfilePictures
Model) which they want to be their profile picture. At the moment the form returns the string of the image URL. How can i make the actual image be in the
drop down so that a user can see all the images before choosing the one they want?
Models.py
class ProfilePicture(models.Model):
image = models.ImageField(upload_to='profile_pics', blank=True)
def __str__(self):
return f'{self.image.url}'
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
bio = models.TextField(default=' Your Bio ', max_length=200)
pic = models.ForeignKey(ProfilePicture, on_delete=models.SET_DEFAULT, default='1')
def __str__(self):
return f'{self.user.username} Profile'
Forms.py
class ProfileUpdateForm(forms.ModelForm):
class Meta:
model = Profile
fields = ['bio','image','pic']
# widgets = {
# 'pic': ImageField(),
# }
Image of the current dropdown list