N
N
Nicknameme2021-05-06 12:50:02
Django
Nicknameme, 2021-05-06 12:50:02

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.
6093b8b64bdef539122336.png
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)


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: Everything works, but I don't know how to change the text.
<h5>{{ profile_form.photo }}</h5>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maksam07, 2021-05-06
@Nicknameme

Source code blog_t/edit.html can you?

I
Ivan Demianov, 2021-05-06
@Vanushka1102

Just make an ImageInputField in FORMS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question