0% found this document useful (0 votes)
33 views4 pages

#89

The document is about adding student results in a school management system. It includes a template for rendering a form to add results. The form allows selecting a subject, session year, student and entering assignment and exam marks. It also includes the view functions to handle form submission and save the results to the database, updating if already exists or creating a new record.

Uploaded by

Shubham Bhade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views4 pages

#89

The document is about adding student results in a school management system. It includes a template for rendering a form to add results. The form allows selecting a subject, session year, student and entering assignment and exam marks. It also includes the view functions to handle form submission and save the results to the database, updating if already exists or creating a new record.

Uploaded by

Shubham Bhade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

{% extends 'base.

html' %}
{% block content %}

<div class="content container-fluid">


<div class="page-header">
<div class="row align-items-center">
<div class="col">
<h3 class="page-title">Add Result</h3>
<ul class="breadcrumb">
<li class="breadcrumb-item"><a
href="subjects.html">Dashboard</a></li>
<li class="breadcrumb-item active">Add Result</li>
</ul>
</div>
</div>
</div>
{% include 'includes/error_msg.html' %}
{% if action is None %}
<form method="post" action="?action=Show-Students">
{% csrf_token %}
<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-12">
<h5 class="form-title"><span>Add
Result</span></h5>
</div>

<div class="col-12 col-sm-6">


<div class="form-group">
<label >Subject</label>
<select class="form-control"
name="subject_id">
<option>-- Select Subject--</option>
{% for i in subjects %}
<option
value="{{i.id}}">{{i.subject_name}}</option>
{% endfor %}

</select>
</div>
</div>

<div class="col-12 col-sm-6">


<div class="form-group">
<label>Session Year</label>
<select class="form-control"
name="session_year_id">
<option>-- Select Session
Year--</option>
{% for i in session_year %}
<option
value="{{i.id}}">{{i.session_start}} TO {{i.session_end}}</option>
{% endfor %}
</select>
</div>
</div>
<br>
<div class="col-10 mr-3">
<button type="submit" class="btn btn-
primary">Fetch Student</button>
</div>
</div>
<hr>
</div>
</div>
</div>
</div>
</form>
{% else %}
<form method="post" action="{% url 'staff_save_result' %}">
{% csrf_token %}
<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-12">
<h5 class="form-title"><span>Add
Result</span></h5>
</div>

<div class="col-12 col-sm-6">


<div class="form-group">
<label >Subject</label>
<select class="form-control"
name="subject_id">
<option
value="{{get_subject.id}}">{{get_subject}}</option>
</select>
</div>
</div>

<div class="col-12 col-sm-6">


<div class="form-group">
<label>Session Year</label>
<select class="form-control"
name="session_year_id">

<option
value="{{get_session.id}}">{{get_session}}</option>

</select>
</div>
</div>
<hr>
<div class="col-12 col-sm-12">
<div class="form-group">
<label>Student List</label>
<select class="form-control"
name="student_id">
{% for i in students %}
<option
value="{{i.admin.id}}">ID{{i.id}}: {{i.admin.first_name}}
{{i.admin.last_name}}</option>
{% endfor %}
</select>
</div>
</div>

<div class="col-12 col-sm-6">


<div class="form-group">

<label>Assignment Marks</label>
<input type="number" class="form-control"
name="assignment_mark">
</div>

</div>
<div class="col-12 col-sm-6">
<div class="form-group">
<label>Exam Marks</label>
<input type="number" class="form-control"
name="Exam_mark">

</div>
</div>

<br>
<div class="col-10 mr-3">
<button type="submit" class="btn btn-
primary">Add Result</button>
</div>
</div>
<hr>
</div>
</div>
</div>
</div>
</form>
{% endif %}
</div>

{% endblock %}

---------------------------------------------------

def STAFF_ADD_RESULT(request):
staff = Staff.objects.get(admin = request.user.id)

subjects = Subject.objects.filter(staff_id = staff)


session_year = Session_Year.objects.all()
action = request.GET.get('action')
get_subject = None
get_session = None
students = None
if action is not None:
if request.method == "POST":
subject_id = request.POST.get('subject_id')
session_year_id = request.POST.get('session_year_id')
get_subject = Subject.objects.get(id = subject_id)
get_session = Session_Year.objects.get(id = session_year_id)

subjects = Subject.objects.filter(id = subject_id)


for i in subjects:
student_id = i.course.id
students = Student.objects.filter(course_id = student_id)

context = {
'subjects':subjects,
'session_year':session_year,
'action':action,
'get_subject':get_subject,
'get_session':get_session,
'students':students,
}

return render(request,'Staff/add_result.html',context)

def STAFF_SAVE_RESULT(request):
if request.method == "POST":
subject_id = request.POST.get('subject_id')
session_year_id = request.POST.get('session_year_id')
student_id = request.POST.get('student_id')
assignment_mark = request.POST.get('assignment_mark')
Exam_mark = request.POST.get('Exam_mark')

get_student = Students.objects.get(admin = student_id)


get_subject = Subjects.objects.get(id=subject_id)

check_exist = StudentResult.objects.filter(subject_id=get_subject,
student_id=get_student).exists()
if check_exist:
result = StudentResult.objects.get(subject_id=get_subject,
student_id=get_student)
result.subject_assignment_marks = assignment_mark
result.subject_exam_marks = Exam_mark
result.save()
messages.success(request, "Successfully Updated Result")
return redirect('staff_add_result')
else:
result = StudentResult(student_id=get_student, subject_id=get_subject,
subject_exam_marks=Exam_mark,
subject_assignment_marks=assignment_mark)
result.save()
messages.success(request, "Successfully Added Result")
return redirect('staff_add_result')

You might also like