Not able to save data from a form Django 4.1

37 views
Skip to first unread message

nef

unread,
Feb 5, 2023, 1:40:36 PM2/5/23
to Django users
Hi everyone,
I am working on a small student application.
I designed a table for storing students' information in which those fields of information are requested at the first registration and those can be updated later or updated during the process. For example, a student's information can update in the process by putting on-hold (update the onhold field) in case that student has been absent for 3 weeks.
The attached file contains my code.
When I fill out the form and submit it, it opens a new form without safe my information.

I also try to create the form directly from the model and send it, but it still not working (saying that there is a mandatory field even when I filled all the fields)
###form.py
class StudentRegistrationForm(ModelForm):
    class Meta:
        model = Student
        fields = "__all__"
###view.py
def addStudent(request):
    form = StudentRegistrationForm()
    if request.method == "POST":
        form = StudentRegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('listStudents')
    return render(request, 'students_management_app/student_template/addStudent.html', {'form': form})


Thank you for your support

Eric


student_code.txt
Reply all
Reply to author
Forward
0 new messages