Answer the question
In order to leave comments, you need to log in
How to change text in django form?
Hello. I made a form so that the user can change the profile picture. But I can't change the text.
I want only the "Choose file" button
Models:
def photo_directory_path(instance, filename):
return 'users/user_{0}/{1}'.format(instance.user.id, filename)
class Profile(models.Model):
GENDER_CHOISCES = [
('Man', 'Man'),
('Woman', 'Woman'),
('Other', 'Other')
]
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
date_of_birth = models.DateField(blank=True, null=True)
photo = models.ImageField(upload_to=photo_directory_path, blank=True)
gender = models.CharField(max_length=50, choices=GENDER_CHOISCES, blank=True)
Facebookurl = models.CharField(max_length=150, blank=True)
steamurl = models.CharField(max_length=150, blank=True)
twitterurl = models.CharField(max_length=150, blank=True)
backimage = models.OneToOneField(BackgroungImageProfile, on_delete=models.CASCADE, null=True, blank=True)
def __str__(self):
return 'Profile for user {}'.format(self.user.username)
class UserEditForm(forms.ModelForm):
class Meta:
model = User
fields = ('first_name', 'email')
class ProfileEditForm(forms.ModelForm):
class Meta:
model = Profile
fields = ('gender', 'Facebookurl', 'steamurl', 'twitterurl', 'photo')
@login_required
def edit(request):
if request.method == 'POST':
user_form = UserEditForm(instance=request.user,data=request.POST)
profile_form = ProfileEditForm(instance=request.user.profile, data=request.POST, files=request.FILES)
if user_form.is_valid() and profile_form.is_valid():
user_form.save()
profile_form.save()
else:
user_form = UserEditForm(instance=request.user)
profile_form = ProfileEditForm(instance=request.user.profile)
return render(request, 'blog_t/edit.html', {'user_form': user_form,'profile_form': profile_form})
<h5>{{ profile_form.photo }}</h5>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question