-1

i have a form and when rendering should have some of the fields pre-filled and disabled with currently logged-in user, django.

This is the rendered django form and under the username field should show only the current logged-in user and not all the registered users.

views.py

@login_required
def teacherRecordForm(request):
    if request.user.is_authenticated:
        teacher_form = TeacherRecordForm
        if request.method == 'POST':
            teacher_form = TeacherRecordForm(request.POST, request.FILES)
            if teacher_form.is_valid():
                teacher_form.save()
                messages.success(request, 'Details Saved Successfully')
                return redirect ('teacher-record-form')
            else:
                messages.success(request, 'check your information provided well')
                return render(request, 'schRecords/teacherRecordForm.html', {'teacher_form':teacher_form})
                
        else:  
            return render(request, 'schRecords/teacherRecordForm.html', {'teacher_form':teacher_form})       
    else:
        messages.success(request, 'kindly sign in first')    
    return redirect('sign-in')
askdebb
  • 1
  • 1
  • this related question should have the answers you need: [*In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?*](https://stackoverflow.com/questions/324477/in-a-django-form-how-do-i-make-a-field-readonly-or-disabled-so-that-it-cannot) – StefanoTrv Aug 14 '23 at 16:46

0 Answers0