Всем привет. Я сделал форму для того что бы пользователь мог поменять фотку в профиле. Но я не могу поменять текст.
Я хочу что бы только была кнопка "Выбрать файл"
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)
Forms:
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')
Views:
@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})
HTML:
<h5>{{ profile_form.photo }}</h5>
Все работает, только я не знаю как поменять текст.