This commit is contained in:
sankalp committed 2025-01-10 14:09:32 +05:45
1 parent 29680072a0
commit 1e79deb319
110 files changed
+18389 -870

No files matched your search

+255 -104
View File
@@ -8,11 +8,16 @@ from app.models import (
Subject,
NewsEvent,
Attendance,
Result,
Marksheet,
Library,
Marksheet,
# Certificate,
SubjectMark,
)
from django.shortcuts import render
from django.urls import path
from django.template.response import TemplateResponse
# BaseUserAdmin to handle common behavior for BaseUser-based models
@@ -27,58 +32,105 @@ class BaseUserAdmin(admin.ModelAdmin):
@admin.register(Teacher)
class TeacherAdmin(BaseUserAdmin):
list_display = ("id", "first_name", "last_name", "email", "phone", "active_status")
search_fields = ("first_name", "last_name", "email", "phone")
list_filter = ("active_status", "gender", "group")
class TeacherAdmin(admin.ModelAdmin):
list_display = ("first_name", "last_name", "email", "phone", "gender", "qualification", "specialization")
search_fields = ("first_name", "last_name", "email", "phone", "specialization")
list_filter = ("gender", "qualification", "date_of_joining")
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path("", self.teacher_list_view, name="teacher_changelist"),
]
return custom_urls + urls
def teacher_list_view(self, request):
teachers = Teacher.objects.all()
context = {
**self.admin_site.each_context(request),
"title": "Teacher List",
"teachers": teachers,
"opts": self.model._meta,
}
return TemplateResponse(request, "Hod/teacher.html", context)
@admin.register(Student)
class StudentAdmin(BaseUserAdmin):
list_display = (
"id",
"first_name",
"last_name",
"father_name",
"mother_name",
"guardian_name",
"email",
"phone",
"course",
"academic_year",
"active_status",
)
search_fields = (
"first_name",
"last_name",
"father_name",
"mother_name",
"email",
"phone",
)
list_filter = ("active_status", "gender", "course", "academic_year")
class StudentAdmin(admin.ModelAdmin):
list_display = ("first_name", "last_name", "email", "phone", "course", "academic_year")
search_fields = ("first_name", "last_name", "email", "phone", "course__name")
list_filter = ("gender", "academic_year", "course")
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path("", self.student_list_view, name="student_changelist"),
]
return custom_urls + urls
def student_list_view(self, request):
students = Student.objects.select_related("course", "academic_year").all()
context = {
**self.admin_site.each_context(request),
"title": "Student List",
"students": students,
"opts": self.model._meta,
}
return TemplateResponse(request, "Hod/student.html", context)
@admin.register(Staff)
class StaffAdmin(BaseUserAdmin):
list_display = (
"id",
"first_name",
"last_name",
"email",
"phone",
"position",
"active_status",
)
search_fields = ("first_name", "last_name", "email", "phone")
list_filter = ("active_status", "position", "group")
class StaffAdmin(admin.ModelAdmin):
list_display = ("first_name", "last_name", "email", "position", "date_of_joining")
search_fields = ("first_name", "last_name", "email", "position")
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path("", self.staff_list_view, name="staff_list"),
]
return custom_urls + urls
def staff_list_view(self, request):
staff_members = Staff.objects.all()
context = {
**self.admin_site.each_context(request),
"title": "Staff List",
"staff_members": staff_members,
}
return TemplateResponse(request, "Hod/staff.html", context)
@admin.register(Course)
class CourseAdmin(admin.ModelAdmin):
list_display = ("id", "name", "level", "course_type", "duration")
list_display = ("name", "level", "course_type", "duration")
list_filter = ("level", "course_type")
search_fields = ("name",)
list_filter = ("course_type",)
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path("", self.course_list_view, name="course_changelist"),
]
return custom_urls + urls
def course_list_view(self, request):
# Get all courses
courses = Course.objects.all().order_by("name")
# Prepare the context with your model's specific fields
context = {
**self.admin_site.each_context(request),
"title": "Course List",
"courses": courses,
"opts": self.model._meta,
"has_add_permission": self.has_add_permission(request),
"level_choices": dict(Course.level_choice),
"course_type_choices": dict(
[("semester", "Semester-based"), ("yearly", "Yearly-based")]
),
}
return TemplateResponse(request, "Hod/add_course.html", context)
@admin.register(AcademicYear)
@@ -86,97 +138,196 @@ class AcademicYearAdmin(admin.ModelAdmin):
list_display = ("id", "year")
search_fields = ("year",)
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path("", self.academic_year_list_view, name="academic_year_changelist"),
]
return custom_urls + urls
def academic_year_list_view(self, request):
# Get all academic years
academic_years = AcademicYear.objects.all().order_by("year")
# Prepare the context with your model's specific fields
context = {
**self.admin_site.each_context(request),
"title": "Academic List",
"academic_years": academic_years,
"opts": self.model._meta,
"has_add_permission": self.has_add_permission(request),
}
return TemplateResponse(request, "Hod/academic_year.html", context)
@admin.register(Subject)
class SubjectAdmin(admin.ModelAdmin):
list_display = ("id", "name", "course", "semester_or_year_number")
search_fields = ("name", "course__name")
list_display = ("name", "course", "semester_or_year_number", "teacher")
search_fields = ("name", "course__name", "teacher__name")
list_filter = ("course", "semester_or_year_number")
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path("", self.subject_list_view, name="subject_changelist"),
]
return custom_urls + urls
def subject_list_view(self, request):
subjects = Subject.objects.select_related("course", "teacher").all().order_by("course__name", "semester_or_year_number")
context = {
**self.admin_site.each_context(request),
"title": "Subjects",
"subjects": subjects,
"opts": self.model._meta,
"has_add_permission": self.has_add_permission(request),
}
return TemplateResponse(request, "Hod/subject.html", context)
@admin.register(NewsEvent)
class NewsEventAdmin(admin.ModelAdmin):
list_display = ("id", "title", "summary", "type", "created_at")
search_fields = ("title", "summary")
list_display = ("title", "type", "created_at")
search_fields = ("title", "summary", "type")
list_filter = ("type", "created_at")
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path("", self.news_event_list_view, name="newsevent_changelist"),
]
return custom_urls + urls
def news_event_list_view(self, request):
news_events = NewsEvent.objects.all().order_by("-created_at")
context = {
**self.admin_site.each_context(request),
"title": "News and Events",
"news_events": news_events,
"opts": self.model._meta,
"has_add_permission": self.has_add_permission(request),
}
return TemplateResponse(request, "Hod/news_events.html", context)
@admin.register(Attendance)
class AttendanceAdmin(admin.ModelAdmin):
list_display = ("id", "student", "subject", "date", "status")
list_display = ("student", "subject", "date", "status")
search_fields = ("student__name", "subject__name", "status")
list_filter = ("status", "date", "subject")
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path("", self.attendance_list_view, name="attendance_changelist"),
]
return custom_urls + urls
def attendance_list_view(self, request):
attendance_records = Attendance.objects.select_related("student", "subject").all().order_by("-date")
context = {
**self.admin_site.each_context(request),
"title": "Attendance Records",
"attendance_records": attendance_records,
"opts": self.model._meta,
"has_add_permission": self.has_add_permission(request),
}
return TemplateResponse(request, "Hod/attendance.html", context)
@admin.register(Result)
class ResultAdmin(admin.ModelAdmin):
list_display = (
"student",
"subject",
"practical_marks",
"exam_marks",
"total_marks",
)
readonly_fields = ("total_marks",)
def save_model(self, request, obj, form, change):
obj.total_marks = obj.get_total()
super().save_model(request, obj, form, change)
# admin.site.register()
@admin.register(Library)
class LibraryAdmin(admin.ModelAdmin):
list_display = ("book_name", "publication", "publication_year", "available")
list_display = ("book_name", "category", "publication", "publication_year", "quantity", "available", "date_added")
search_fields = ("book_name", "category", "publication")
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path("", self.library_list_view, name="library_changelist"),
]
return custom_urls + urls
def library_list_view(self, request):
books = Library.objects.all().order_by("-date_added")
context = {
**self.admin_site.each_context(request),
"title": "Library",
"books": books,
"opts": self.model._meta,
"has_add_permission": self.has_add_permission(request),
}
return TemplateResponse(request, "Hod/library.html", context)
class SubjectMarkInline(admin.TabularInline):
model = SubjectMark
extra = 1
fields = (
"subject",
"obtained_theory_marks",
"total_theory_marks",
"obtained_practical_marks",
"total_practical_marks",
"total_marks",
)
readonly_fields = ("total_marks",)
class SubjectMarkInline(admin.TabularInline):
model = SubjectMark
extra = 1 # Number of extra forms to display
fields = (
'subject',
'obtained_practical_marks',
'total_practical_marks',
'obtained_theory_marks',
'total_theory_marks',
'total_marks',
)
readonly_fields = ('total_marks',) # Make total_marks read-only
def save_related(self, request, formset, change):
super().save_related(request, formset, change)
for marksheet in formset.instance:
marksheet.save() # Ensure the Marksheet instance saves after each inline
@admin.register(Marksheet)
class MarksheetAdmin(admin.ModelAdmin):
inlines = [SubjectMarkInline]
list_display = ["student", "course", "total_marks", "obtained_marks", "grade"]
readonly_fields = ["total_marks", "obtained_marks", "grade"]
list_display = ("student", "course", "total_marks", "obtained_marks", "grade")
list_filter = ("course", "grade")
search_fields = ("student__first_name", "student__last_name", "course__name")
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path("", self.marksheet_list_view, name="marksheet_changelist"),
]
return custom_urls + urls
# class SubjectMarkInline(admin.TabularInline):
# model = SubjectMark
# extra = 1
# fields = (
# "subject",
# "obtained_theory_marks",
# "total_theory_marks",
# "obtained_practical_marks",
# "total_practical_marks",
# "total_marks",
# )
# readonly_fields = ("total_marks",)
#
#
# @admin.register(Marksheet)
# class MarksheetAdmin(admin.ModelAdmin):
# list_display = ["student", "course", "total_marks", "obtained_marks", "grade"]
# list_filter = ["grade", "course"]
# search_fields = ["student__first_name", "student__last_name", "course__name"]
# readonly_fields = ["total_marks", "obtained_marks", "grade"]
# inlines = [SubjectMarkInline]
#
# fieldsets = (
# ("Student Information", {"fields": ("student", "course")}),
# (
# "Results",
# {
# "fields": ("total_marks", "obtained_marks", "grade"),
# "classes": ("collapse",),
# },
# ),
# )
def marksheet_list_view(self, request):
marksheets = Marksheet.objects.select_related("student", "course").all()
context = {
**self.admin_site.each_context(request),
"title": "Marksheet List",
"marksheets": marksheets,
"opts": self.model._meta,
"has_add_permission": self.has_add_permission(request),
}
return TemplateResponse(request, "Hod/marksheet.html", context)
# @admin.register(Certificate)
# class CertificateAdmin(admin.ModelAdmin):
# list_display = ("title", "student", "course", "issued_date", "is_verified")
# search_fields = ("student__first_name", "student__last_name", "course__name", "title")
# list_filter = ("is_verified", "issued_date")
# # Optionally, you can add actions for verification or custom actions
# actions = ["mark_verified", "mark_unverified"]
# def mark_verified(self, request, queryset):
# queryset.update(is_verified=True)
# def mark_unverified(self, request, queryset):
# queryset.update(is_verified=False)
# mark_verified.short_description = "Mark selected certificates as verified"
# mark_unverified.short_description = "Mark selected certificates as unverified"
+61 -14
View File
@@ -1,4 +1,4 @@
# Generated by Django 5.1.4 on 2025-01-07 17:39
# Generated by Django 5.1.4 on 2025-01-09 17:58
import django.core.validators
import django.db.models.deletion
@@ -33,7 +33,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('level', models.CharField(choices=[('Basic', 'Basic'), ('Primary', 'Primary'), ('Secondary', 'Secondary'), ('Vocational Traning', 'Vocational Traning'), ('Higher Secondary', 'Higher Secondary'), ('Graduation', 'Graduation'), ('Post Graduation', 'Post Graduation')], max_length=45)),
('level', models.CharField(choices=[('basic', 'Basic'), ('primary', 'Primary'), ('secondary', 'Secondary'), ('vocational traning', 'Vocational Traning'), ('higher secondary', 'Higher Secondary'), ('graduation', 'Graduation'), ('post graduation', 'Post Graduation')], max_length=45)),
('course_type', models.CharField(choices=[('semester', 'Semester-based'), ('yearly', 'Yearly-based')], max_length=10)),
('duration', models.PositiveIntegerField()),
],
@@ -49,7 +49,7 @@ class Migration(migrations.Migration):
('category', models.CharField(max_length=255)),
('book_name', models.CharField(max_length=255)),
('description', models.CharField(max_length=255)),
('author', models.CharField(max_length=255)),
('publication', models.CharField(max_length=255)),
('publication_year', models.PositiveIntegerField()),
('quantity', models.PositiveIntegerField()),
('available', models.CharField(choices=[('Y', 'Yes'), ('N', 'NO')], max_length=1)),
@@ -83,11 +83,11 @@ class Migration(migrations.Migration):
('middle_name', models.CharField(blank=True, max_length=255, null=True)),
('last_name', models.CharField(max_length=255)),
('email', models.EmailField(max_length=255, unique=True)),
('phone', models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')])),
('phone', models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\d{10}$')])),
('username', models.CharField(blank=True, max_length=255, null=True, unique=True)),
('password', models.CharField(max_length=255)),
('gender', models.CharField(choices=[('M', 'Male'), ('F', 'Female')], max_length=1)),
('position', models.CharField(choices=[('Lab Assistant', 'Lab Assistant'), ('Librarian', 'Librarian'), ('Accountant', 'Accountant'), ('Guard', 'Guard'), ('Driver', 'Driver'), ('Helper', 'Helper'), ('Cleaner', 'Cleaner')], max_length=255)),
('position', models.CharField(choices=[('lab Assistant', 'Lab Assistant'), ('librarian', 'Librarian'), ('accountant', 'Accountant'), ('guard', 'Guard'), ('driver', 'Driver'), ('helper', 'Helper'), ('cleaner', 'Cleaner')], max_length=255)),
('address', models.CharField(max_length=255)),
('marital_status', models.CharField(choices=[('married', 'Married'), ('widowed', 'Widowed'), ('separated', 'Separated'), ('divorced', 'Divorced'), ('single', 'Single')], max_length=10)),
('date_of_joining', models.DateField()),
@@ -108,24 +108,24 @@ class Migration(migrations.Migration):
('middle_name', models.CharField(blank=True, max_length=255, null=True)),
('last_name', models.CharField(max_length=255)),
('email', models.EmailField(max_length=255, unique=True)),
('phone', models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')])),
('phone', models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\d{10}$')])),
('username', models.CharField(blank=True, max_length=255, null=True, unique=True)),
('password', models.CharField(max_length=255)),
('address', models.CharField(max_length=255)),
('date_of_birth', models.DateField()),
('gender', models.CharField(choices=[('M', 'Male'), ('F', 'Female')], max_length=1)),
('address', models.CharField(max_length=255)),
('father_name', models.CharField(max_length=100)),
('father_phone_no', models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')])),
('father_phone_no', models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\d{10}$')])),
('father_email', models.EmailField(blank=True, max_length=254, null=True)),
('father_occupation', models.CharField(choices=[('Agriculture', 'Agriculture'), ('Banker', 'Banker'), ('Business', 'Business'), ('Doctor', 'Doctor'), ('Farmer', 'Farmer'), ('Fisherman', 'Fisherman'), ('Public Service', 'Public Service'), ('Private Service', 'Private Service'), ('Shopkeeper', 'Shopkeeper'), ('Driver', 'Driver'), ('Worker', 'Worker'), ('N/A', 'N/A')], default='N/A', max_length=45)),
('father_occupation', models.CharField(choices=[('agriculture', 'Agriculture'), ('banker', 'Banker'), ('business', 'Business'), ('doctor', 'Doctor'), ('farmer', 'Farmer'), ('fisherman', 'Fisherman'), ('public service', 'Public Service'), ('private service', 'Private Service'), ('shopkeeper', 'Shopkeeper'), ('driver', 'Driver'), ('worker', 'Worker'), ('N/A', 'N/A')], default='N/A', max_length=45)),
('mother_name', models.CharField(max_length=100)),
('mother_phone_no', models.CharField(blank=True, max_length=10, null=True, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')])),
('mother_phone_no', models.CharField(blank=True, max_length=10, null=True, validators=[django.core.validators.RegexValidator('^\\d{10}$')])),
('mother_email', models.EmailField(blank=True, max_length=254, null=True)),
('mother_occupation', models.CharField(choices=[('Agriculture', 'Agriculture'), ('Banker', 'Banker'), ('Business', 'Business'), ('Doctor', 'Doctor'), ('Farmer', 'Farmer'), ('Fisherman', 'Fisherman'), ('Public Service', 'Public Service'), ('Private Service', 'Private Service'), ('Shopkeeper', 'Shopkeeper'), ('Driver', 'Driver'), ('HouseWife', 'HouseWife'), ('Worker', 'Worker'), ('N/A', 'N/A')], default='N/A', max_length=45)),
('mother_occupation', models.CharField(choices=[('agriculture', 'Agriculture'), ('banker', 'Banker'), ('business', 'Business'), ('doctor', 'Doctor'), ('farmer', 'Farmer'), ('fisherman', 'Fisherman'), ('public service', 'Public Service'), ('private service', 'Private Service'), ('shopkeeper', 'Shopkeeper'), ('driver', 'Driver'), ('houseWife', 'HouseWife'), ('worker', 'Worker'), ('N/A', 'N/A')], default='N/A', max_length=45)),
('guardian_name', models.CharField(max_length=100)),
('guardian_phone_no', models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')])),
('guardian_phone_no', models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\d{10}$')])),
('guardian_email', models.EmailField(blank=True, max_length=254, null=True)),
('relationship_with_student', models.CharField(choices=[('Father', 'Father'), ('Mother', 'Mother'), ('Brother', 'Brother'), ('Sister', 'Sister'), ('Uncle', 'Uncle'), ('Aunt', 'Aunt'), ('Grandfather', 'Grandfather')], max_length=45)),
('relationship_with_student', models.CharField(choices=[('father', 'Father'), ('mother', 'Mother'), ('brother', 'Brother'), ('sister', 'Sister'), ('uncle', 'Uncle'), ('aunt', 'Aunt'), ('grandfather', 'Grandfather')], max_length=45)),
('academic_year', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.academicyear')),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.course')),
('group', models.ManyToManyField(blank=True, to='auth.group')),
@@ -136,6 +136,37 @@ class Migration(migrations.Migration):
'verbose_name_plural': 'Students',
},
),
migrations.CreateModel(
name='Marksheet',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('total_marks', models.PositiveIntegerField(default=Decimal('0.00'), help_text='Total marks for the course', validators=[django.core.validators.MinValueValidator(1)])),
('obtained_marks', models.PositiveIntegerField(default=Decimal('0.00'), help_text='Total marks obtained by the student', validators=[django.core.validators.MinValueValidator(0)])),
('grade', models.CharField(blank=True, choices=[('A+', 'A+'), ('A', 'A'), ('B+', 'B+'), ('B', 'B'), ('C+', 'C+'), ('C', 'C'), ('D', 'D'), ('E', 'E')], help_text='Grade assigned based on marks', max_length=2, null=True)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='marksheets', to='app.course')),
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='marksheets', to='app.student')),
],
options={
'verbose_name': 'Marksheet',
'verbose_name_plural': 'Marksheets',
'unique_together': {('student', 'course')},
},
),
migrations.CreateModel(
name='Certificate',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('title', models.CharField(max_length=255)),
('description', models.TextField(blank=True, null=True)),
('issue_date', models.DateField(auto_now_add=True)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.course')),
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.student')),
],
options={
'verbose_name': 'Certificate',
'verbose_name_plural': 'Certificate',
},
),
migrations.CreateModel(
name='Subject',
fields=[
@@ -187,7 +218,7 @@ class Migration(migrations.Migration):
('middle_name', models.CharField(blank=True, max_length=255, null=True)),
('last_name', models.CharField(max_length=255)),
('email', models.EmailField(max_length=255, unique=True)),
('phone', models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')])),
('phone', models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\d{10}$')])),
('username', models.CharField(blank=True, max_length=255, null=True, unique=True)),
('password', models.CharField(max_length=255)),
('address', models.CharField(max_length=255)),
@@ -209,4 +240,20 @@ class Migration(migrations.Migration):
name='teacher',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='subjects', to='app.teacher'),
),
migrations.CreateModel(
name='SubjectMark',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('obtained_practical_marks', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=5)),
('total_practical_marks', models.DecimalField(decimal_places=2, default=Decimal('20.00'), max_digits=5)),
('obtained_theory_marks', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=5)),
('total_theory_marks', models.DecimalField(decimal_places=2, default=Decimal('80.00'), max_digits=5)),
('total_marks', models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=5)),
('marksheet', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subject_marks', to='app.marksheet')),
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subject_marks', to='app.subject')),
],
options={
'unique_together': {('marksheet', 'subject')},
},
),
]
@@ -0,0 +1,44 @@
# Generated by Django 5.1.4 on 2025-01-09 18:06
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='staff',
name='phone',
field=models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')]),
),
migrations.AlterField(
model_name='student',
name='father_phone_no',
field=models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')]),
),
migrations.AlterField(
model_name='student',
name='guardian_phone_no',
field=models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')]),
),
migrations.AlterField(
model_name='student',
name='mother_phone_no',
field=models.CharField(blank=True, max_length=10, null=True, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')]),
),
migrations.AlterField(
model_name='student',
name='phone',
field=models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')]),
),
migrations.AlterField(
model_name='teacher',
name='phone',
field=models.CharField(max_length=10, validators=[django.core.validators.RegexValidator('^\\+?1?\\d{9,15}$')]),
),
]
@@ -1,18 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 05:51
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('app', '0001_initial'),
]
operations = [
migrations.RenameField(
model_name='library',
old_name='author',
new_name='publication',
),
]
@@ -0,0 +1,53 @@
# Generated by Django 5.1.4 on 2025-01-10 06:17
import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0002_alter_staff_phone_alter_student_father_phone_no_and_more'),
]
operations = [
migrations.AlterModelOptions(
name='certificate',
options={'verbose_name': 'Certificate', 'verbose_name_plural': 'Certificates'},
),
migrations.RemoveField(
model_name='certificate',
name='issue_date',
),
migrations.AddField(
model_name='certificate',
name='certificate_file',
field=models.FileField(blank=True, null=True, upload_to='certificates/'),
),
migrations.AddField(
model_name='certificate',
name='is_verified',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='certificate',
name='issued_date',
field=models.DateField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name='certificate',
name='course',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='certificates', to='app.course'),
),
migrations.AlterField(
model_name='certificate',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='certificate',
name='student',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='certificates', to='app.student'),
),
]
@@ -1,72 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 07:33
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0002_rename_author_library_publication'),
]
operations = [
migrations.AlterField(
model_name='course',
name='level',
field=models.CharField(choices=[('basic', 'Basic'), ('primary', 'Primary'), ('secondary', 'Secondary'), ('vocational traning', 'Vocational Traning'), ('higher secondary', 'Higher Secondary'), ('graduation', 'Graduation'), ('post graduation', 'Post Graduation')], max_length=45),
),
migrations.AlterField(
model_name='staff',
name='position',
field=models.CharField(choices=[('lab Assistant', 'Lab Assistant'), ('librarian', 'Librarian'), ('accountant', 'Accountant'), ('guard', 'Guard'), ('driver', 'Driver'), ('helper', 'Helper'), ('cleaner', 'Cleaner')], max_length=255),
),
migrations.AlterField(
model_name='student',
name='father_occupation',
field=models.CharField(choices=[('agriculture', 'Agriculture'), ('banker', 'Banker'), ('business', 'Business'), ('doctor', 'Doctor'), ('farmer', 'Farmer'), ('fisherman', 'Fisherman'), ('public service', 'Public Service'), ('private service', 'Private Service'), ('shopkeeper', 'Shopkeeper'), ('driver', 'Driver'), ('worker', 'Worker'), ('N/A', 'N/A')], default='N/A', max_length=45),
),
migrations.AlterField(
model_name='student',
name='mother_occupation',
field=models.CharField(choices=[('agriculture', 'Agriculture'), ('banker', 'Banker'), ('business', 'Business'), ('doctor', 'Doctor'), ('farmer', 'Farmer'), ('fisherman', 'Fisherman'), ('public service', 'Public Service'), ('private service', 'Private Service'), ('shopkeeper', 'Shopkeeper'), ('driver', 'Driver'), ('houseWife', 'HouseWife'), ('worker', 'Worker'), ('N/A', 'N/A')], default='N/A', max_length=45),
),
migrations.AlterField(
model_name='student',
name='relationship_with_student',
field=models.CharField(choices=[('father', 'Father'), ('mother', 'Mother'), ('brother', 'Brother'), ('sister', 'Sister'), ('uncle', 'Uncle'), ('aunt', 'Aunt'), ('grandfather', 'Grandfather')], max_length=45),
),
migrations.CreateModel(
name='Certificate',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('title', models.CharField(max_length=255)),
('description', models.TextField(blank=True, null=True)),
('issue_date', models.DateField(auto_now_add=True)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.course')),
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.student')),
],
options={
'verbose_name': 'Certificate',
'verbose_name_plural': 'Certificate',
},
),
migrations.CreateModel(
name='Marksheet',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('marks_obtained', models.DecimalField(decimal_places=2, max_digits=5)),
('total_marks', models.DecimalField(decimal_places=2, max_digits=5)),
('grade', models.CharField(blank=True, max_length=2, null=True)),
('exam_date', models.DateField()),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='marksheets', to='app.course')),
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='marksheets', to='app.student')),
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='marksheets', to='app.subject')),
],
options={
'verbose_name': 'Marksheet',
'verbose_name_plural': 'Marksheets',
'unique_together': {('student', 'course', 'subject')},
},
),
]
@@ -1,34 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 07:39
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0003_alter_course_level_alter_staff_position_and_more'),
]
operations = [
migrations.AlterField(
model_name='marksheet',
name='exam_date',
field=models.DateField(help_text='Date of the examination'),
),
migrations.AlterField(
model_name='marksheet',
name='grade',
field=models.CharField(blank=True, choices=[('A+', 'Excellent'), ('A', 'Very Good'), ('B', 'Good'), ('C', 'Average'), ('D', 'Below Average'), ('F', 'Fail')], help_text='Grade assigned based on marks', max_length=2, null=True),
),
migrations.AlterField(
model_name='marksheet',
name='marks_obtained',
field=models.PositiveIntegerField(help_text='Marks obtained by the student', validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AlterField(
model_name='marksheet',
name='total_marks',
field=models.PositiveIntegerField(help_text='Total marks for the subject', validators=[django.core.validators.MinValueValidator(1)]),
),
]
@@ -0,0 +1,31 @@
# Generated by Django 5.1.4 on 2025-01-10 06:21
import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0003_alter_certificate_options_and_more'),
]
operations = [
migrations.CreateModel(
name='CharacterCertificate',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('issued_date', models.DateField(default=django.utils.timezone.now)),
('issued_by', models.CharField(max_length=255)),
('remarks', models.TextField()),
('is_verified', models.BooleanField(default=False)),
('certificate_file', models.FileField(blank=True, null=True, upload_to='character_certificates/')),
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='character_certificates', to='app.student')),
],
options={
'verbose_name': 'Character Certificate',
'verbose_name_plural': 'Character Certificates',
},
),
]
@@ -1,19 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 07:51
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0004_alter_marksheet_exam_date_alter_marksheet_grade_and_more'),
]
operations = [
migrations.AddField(
model_name='marksheet',
name='subj_result',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='app.result'),
),
]
@@ -0,0 +1,23 @@
# Generated by Django 5.1.4 on 2025-01-10 06:22
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('app', '0004_charactercertificate'),
]
operations = [
migrations.RemoveField(
model_name='charactercertificate',
name='student',
),
migrations.DeleteModel(
name='Certificate',
),
migrations.DeleteModel(
name='CharacterCertificate',
),
]
@@ -1,4 +1,4 @@
# Generated by Django 5.1.4 on 2025-01-08 09:16
# Generated by Django 5.1.4 on 2025-01-10 06:49
import django.core.validators
from decimal import Decimal
@@ -8,23 +8,23 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0012_alter_marksheet_obtained_marks_and_more'),
('app', '0005_remove_charactercertificate_student_and_more'),
]
operations = [
migrations.AlterField(
model_name='marksheet',
name='grade',
field=models.CharField(blank=True, choices=[('A+', 'Excellent'), ('A', 'Very Good'), ('B+', 'Good'), ('B', ''), ('C+', 'Average'), ('C', ''), ('D+', 'Below Average'), ('D', 'Fail')], help_text='Grade assigned based on marks', max_length=2, null=True),
field=models.CharField(blank=True, choices=[('A+', 'A+'), ('A', 'A'), ('B+', 'B+'), ('B', 'B'), ('C+', 'C+'), ('C', 'C'), ('D', 'D'), ('E', 'E')], max_length=2, null=True),
),
migrations.AlterField(
model_name='marksheet',
name='obtained_marks',
field=models.PositiveIntegerField(default=Decimal('0.00'), help_text='Total marks obtained by the student', validators=[django.core.validators.MinValueValidator(0)]),
field=models.PositiveIntegerField(default=Decimal('0.00'), validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AlterField(
model_name='marksheet',
name='total_marks',
field=models.PositiveIntegerField(default=Decimal('0.00'), help_text='Total marks for the course', validators=[django.core.validators.MinValueValidator(1)]),
field=models.PositiveIntegerField(default=Decimal('0.00'), validators=[django.core.validators.MinValueValidator(1)]),
),
]
@@ -1,25 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 07:53
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('app', '0005_marksheet_subj_result'),
]
operations = [
migrations.AlterUniqueTogether(
name='marksheet',
unique_together={('student', 'course')},
),
migrations.RemoveField(
model_name='marksheet',
name='exam_date',
),
migrations.RemoveField(
model_name='marksheet',
name='subject',
),
]
@@ -1,4 +1,4 @@
# Generated by Django 5.1.4 on 2025-01-08 08:43
# Generated by Django 5.1.4 on 2025-01-10 06:50
from decimal import Decimal
from django.db import migrations, models
@@ -7,13 +7,13 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0008_remove_subjectmark_marks_obtained_and_more'),
('app', '0006_alter_marksheet_grade_alter_marksheet_obtained_marks_and_more'),
]
operations = [
migrations.AlterField(
model_name='subjectmark',
name='total_marks',
field=models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=5),
field=models.DecimalField(blank=True, decimal_places=2, default=Decimal('0.00'), max_digits=5, null=True),
),
]
@@ -1,46 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 08:29
import django.core.validators
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0006_alter_marksheet_unique_together_and_more'),
]
operations = [
migrations.RemoveField(
model_name='marksheet',
name='marks_obtained',
),
migrations.RemoveField(
model_name='marksheet',
name='subj_result',
),
migrations.AddField(
model_name='marksheet',
name='obtained_marks',
field=models.PositiveIntegerField(default=0, help_text='Total marks obtained by the student', validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AlterField(
model_name='marksheet',
name='total_marks',
field=models.PositiveIntegerField(help_text='Total marks for the course', validators=[django.core.validators.MinValueValidator(1)]),
),
migrations.CreateModel(
name='SubjectMark',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('marks_obtained', models.PositiveIntegerField(help_text='Marks obtained in this subject', validators=[django.core.validators.MinValueValidator(0)])),
('total_marks', models.PositiveIntegerField(help_text='Total marks for this subject', validators=[django.core.validators.MinValueValidator(1)])),
('marksheet', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subject_marks', to='app.marksheet')),
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='subject_marks', to='app.subject')),
],
options={
'unique_together': {('marksheet', 'subject')},
},
),
]
@@ -0,0 +1,25 @@
# Generated by Django 5.1.4 on 2025-01-10 06:51
import django.core.validators
from decimal import Decimal
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0007_alter_subjectmark_total_marks'),
]
operations = [
migrations.AlterField(
model_name='marksheet',
name='total_marks',
field=models.PositiveIntegerField(blank=True, default=Decimal('0.00'), null=True, validators=[django.core.validators.MinValueValidator(1)]),
),
migrations.AlterField(
model_name='subjectmark',
name='total_marks',
field=models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=5),
),
]
@@ -1,43 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 08:42
from decimal import Decimal
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0007_remove_marksheet_marks_obtained_and_more'),
]
operations = [
migrations.RemoveField(
model_name='subjectmark',
name='marks_obtained',
),
migrations.AddField(
model_name='subjectmark',
name='obtained_practical_marks',
field=models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=5),
),
migrations.AddField(
model_name='subjectmark',
name='obtained_theory_marks',
field=models.DecimalField(decimal_places=2, default=Decimal('0.00'), max_digits=5),
),
migrations.AddField(
model_name='subjectmark',
name='total_practical_marks',
field=models.DecimalField(decimal_places=2, default=Decimal('20.00'), max_digits=5),
),
migrations.AddField(
model_name='subjectmark',
name='total_theory_marks',
field=models.DecimalField(decimal_places=2, default=Decimal('80.00'), max_digits=5),
),
migrations.AlterField(
model_name='subjectmark',
name='total_marks',
field=models.DecimalField(decimal_places=2, default=Decimal('0.00'), editable=False, max_digits=5),
),
]
@@ -0,0 +1,20 @@
# Generated by Django 5.1.4 on 2025-01-10 06:52
import django.core.validators
from decimal import Decimal
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0008_alter_marksheet_total_marks_and_more'),
]
operations = [
migrations.AlterField(
model_name='marksheet',
name='total_marks',
field=models.PositiveIntegerField(blank=True, default=Decimal('0.00'), null=True, validators=[django.core.validators.MinValueValidator(0)]),
),
]
@@ -1,19 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 08:51
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0009_alter_subjectmark_total_marks'),
]
operations = [
migrations.AlterField(
model_name='marksheet',
name='total_marks',
field=models.PositiveIntegerField(default=0, help_text='Total marks for the course', validators=[django.core.validators.MinValueValidator(1)]),
),
]
@@ -1,19 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 08:53
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0010_alter_marksheet_total_marks'),
]
operations = [
migrations.AlterField(
model_name='marksheet',
name='total_marks',
field=models.PositiveIntegerField(help_text='Total marks for the course', validators=[django.core.validators.MinValueValidator(1)]),
),
]
@@ -1,25 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 09:01
import django.core.validators
from decimal import Decimal
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0011_alter_marksheet_total_marks'),
]
operations = [
migrations.AlterField(
model_name='marksheet',
name='obtained_marks',
field=models.PositiveIntegerField(default=Decimal('0.00'), editable=False, help_text='Total marks obtained by the student', validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AlterField(
model_name='marksheet',
name='total_marks',
field=models.PositiveIntegerField(default=Decimal('0.00'), editable=False, help_text='Total marks for the course', validators=[django.core.validators.MinValueValidator(1)]),
),
]
@@ -1,18 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 09:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0013_alter_marksheet_grade_alter_marksheet_obtained_marks_and_more'),
]
operations = [
migrations.AlterField(
model_name='marksheet',
name='grade',
field=models.CharField(blank=True, choices=[('A+', 'Excellent'), ('A', 'Very Good'), ('B+', 'Good'), ('B', 'G'), ('C+', 'Average'), ('C', 'A'), ('D+', 'Below Average'), ('D', 'Fail')], help_text='Grade assigned based on marks', max_length=2, null=True),
),
]
@@ -1,18 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 09:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0014_alter_marksheet_grade'),
]
operations = [
migrations.AlterField(
model_name='marksheet',
name='grade',
field=models.CharField(blank=True, choices=[('A+', 'Outstanding'), ('A', 'Excellent'), ('B+', 'Very Good'), ('B', 'Good'), ('C+', 'Above Average'), ('C', 'Average'), ('D', 'Below Average'), ('E', 'Fail')], help_text='Grade assigned based on marks', max_length=2, null=True),
),
]
@@ -1,18 +0,0 @@
# Generated by Django 5.1.4 on 2025-01-08 09:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0015_alter_marksheet_grade'),
]
operations = [
migrations.AlterField(
model_name='marksheet',
name='grade',
field=models.CharField(blank=True, choices=[('A+', 'A+'), ('A', 'A'), ('B+', 'B+'), ('B', 'B'), ('C+', 'C+'), ('C', 'C'), ('D', 'D'), ('E', 'E')], help_text='Grade assigned based on marks', max_length=2, null=True),
),
]
+42 -149
View File
@@ -6,7 +6,7 @@ import random
from decimal import Decimal
from datetime import time, timedelta, datetime
from django.core.validators import MinValueValidator, MaxValueValidator
from django.utils import timezone
# Abstract BaseUser Model
class BaseUser(models.Model):
@@ -27,15 +27,12 @@ class BaseUser(models.Model):
abstract = True
def save(self, *args, **kwargs):
# Generate a username if not provided
if not self.username:
self.username = f"{self.first_name.lower()}_{random.randint(1000, 9999)}"
# Hash the password if new or not already hashed
if self._state.adding or not self.password.startswith("pbkdf2_"):
self.password = make_password(self.password)
# Sync with Django User model
if not self.user:
self.user = User.objects.create(
username=self.username,
@@ -351,63 +348,41 @@ class Library(models.Model):
verbose_name = "Library"
verbose_name_plural = "Library"
# class Certificate(models.Model):
# title = models.CharField(max_length=255)
# student = models.ForeignKey("Student", on_delete=models.CASCADE, related_name="certificates")
# course = models.ForeignKey("Course", on_delete=models.CASCADE, related_name="certificates")
# issued_date = models.DateField(default=timezone.now)
# is_verified = models.BooleanField(default=False)
# certificate_file = models.FileField(upload_to="certificates/", blank=True, null=True)
# description = models.TextField(blank=True, null=True)
# def __str__(self):
# return f"{self.title} - {self.student.first_name} {self.student.last_name}"
# class Meta:
# verbose_name = "Certificate"
# verbose_name_plural = "Certificates"
class Certificate(models.Model):
id = models.AutoField(primary_key=True)
student = models.ForeignKey("Student", on_delete=models.CASCADE)
course = models.ForeignKey("Course", on_delete=models.CASCADE)
title = models.CharField(max_length=255)
description = models.TextField(blank=True, null=True)
issue_date = models.DateField(auto_now_add=True)
class Meta:
verbose_name = "Certificate"
verbose_name_plural = "Certificate"
class Marksheet(models.Model):
student = models.ForeignKey(
"Student", on_delete=models.CASCADE, related_name="marksheets"
)
course = models.ForeignKey(
"Course", on_delete=models.CASCADE, related_name="marksheets"
)
total_marks = models.PositiveIntegerField(
validators=[MinValueValidator(1)],
default=Decimal("0.00"),
help_text="Total marks for the course",
# editable=False,
)
obtained_marks = models.PositiveIntegerField(
validators=[MinValueValidator(0)],
default=Decimal("0.00"),
help_text="Total marks obtained by the student",
# editable=False,
)
grade = models.CharField(
max_length=2,
choices=[
# ("A+", "Outstanding"),
# ("A", "Excellent"),
# ("B+", "Very Good"),
# ("B", "Good"),
# ("C+", "Above Average"),
# ("C", "Average"),
# ("D", "Below Average"),
# ("E", "Fail"),
("A+", "A+"),
("A", "A"),
("B+", "B+"),
("B", "B"),
("C+", "C+"),
("C", "C"),
("D", "D"),
("E", "E"),
],
blank=True,
null=True,
help_text="Grade assigned based on marks",
)
student = models.ForeignKey("Student", on_delete=models.CASCADE, related_name="marksheets")
course = models.ForeignKey("Course", on_delete=models.CASCADE, related_name="marksheets")
total_marks = models.PositiveIntegerField(validators=[MinValueValidator(0)], default=Decimal("0.00"), blank=True, null=True)
obtained_marks = models.PositiveIntegerField(validators=[MinValueValidator(0)], default=Decimal("0.00"))
grade = models.CharField(max_length=2, choices=[
("A+", "A+"),
("A", "A"),
("B+", "B+"),
("B", "B"),
("C+", "C+"),
("C", "C"),
("D", "D"),
("E", "E"),
], blank=True, null=True)
class Meta:
verbose_name = "Marksheet"
@@ -416,17 +391,8 @@ class Marksheet(models.Model):
def calculate_totals(self):
subject_marks = self.subject_marks.all()
total_marks = sum(
subject.total_practical_marks + subject.total_theory_marks
for subject in subject_marks
) or Decimal("0.00")
obtained_marks = sum(
subject.obtained_practical_marks + subject.obtained_theory_marks
for subject in subject_marks
) or Decimal("0.00")
total_marks = sum(subject.total_practical_marks + subject.total_theory_marks for subject in subject_marks) or Decimal("0.00")
obtained_marks = sum(subject.obtained_practical_marks + subject.obtained_theory_marks for subject in subject_marks) or Decimal("0.00")
return total_marks, obtained_marks
def save(self, *args, **kwargs):
@@ -461,97 +427,24 @@ class Marksheet(models.Model):
class SubjectMark(models.Model):
marksheet = models.ForeignKey(
Marksheet, on_delete=models.CASCADE, related_name="subject_marks"
)
subject = models.ForeignKey(
"Subject", on_delete=models.CASCADE, related_name="subject_marks"
)
obtained_practical_marks = models.DecimalField(
max_digits=5, decimal_places=2, default=Decimal("0.00")
)
total_practical_marks = models.DecimalField(
max_digits=5, decimal_places=2, default=Decimal("20.00")
)
obtained_theory_marks = models.DecimalField(
max_digits=5, decimal_places=2, default=Decimal("0.00")
)
total_theory_marks = models.DecimalField(
max_digits=5, decimal_places=2, default=Decimal("80.00")
)
total_marks = models.DecimalField(
max_digits=5, decimal_places=2, default=Decimal("0.00")
)
marksheet = models.ForeignKey(Marksheet, on_delete=models.CASCADE, related_name="subject_marks")
subject = models.ForeignKey("Subject", on_delete=models.CASCADE, related_name="subject_marks")
obtained_practical_marks = models.DecimalField(max_digits=5, decimal_places=2, default=Decimal("0.00"))
total_practical_marks = models.DecimalField(max_digits=5, decimal_places=2, default=Decimal("20.00"))
obtained_theory_marks = models.DecimalField(max_digits=5, decimal_places=2, default=Decimal("0.00"))
total_theory_marks = models.DecimalField(max_digits=5, decimal_places=2, default=Decimal("80.00"))
total_marks = models.DecimalField(max_digits=5, decimal_places=2, default=Decimal("0.00"))
def get_total(self):
return Decimal(str(self.obtained_practical_marks or 0)) + Decimal(
str(self.obtained_theory_marks or 0)
)
return Decimal(str(self.obtained_practical_marks or 0)) + Decimal(str(self.obtained_theory_marks or 0))
def save(self, *args, **kwargs):
self.total_marks = self.get_total()
super().save(*args, **kwargs)
self.marksheet.save()
self.marksheet.save() # Trigger the marksheet save to recalculate totals
class Meta:
unique_together = ("marksheet", "subject")
def __str__(self):
return f"{self.subject.name} - {self.marksheet.student.first_name}"
# class Marksheet(models.Model):
# student = models.ForeignKey(
# "Student", on_delete=models.CASCADE, related_name="marksheets"
# )
# course = models.ForeignKey(
# "Course", on_delete=models.CASCADE, related_name="marksheets"
# )
# subj_result = models.ForeignKey(
# "Result", on_delete=models.CASCADE, related_name="marksheets", null=True
# )
# marks_obtained = models.PositiveIntegerField(
# validators=[MinValueValidator(0)], help_text="Marks obtained by the student"
# )
# total_marks = models.PositiveIntegerField(
# validators=[MinValueValidator(1)], help_text="Total marks for the subject"
# )
# grade = models.CharField(
# max_length=2,
# choices=[
# ("A+", "Excellent"),
# ("A", "Very Good"),
# ("B", "Good"),
# ("C", "Average"),
# ("D", "Below Average"),
# ("F", "Fail"),
# ],
# blank=True,
# null=True,
# help_text="Grade assigned based on marks",
# )
#
# class Meta:
# verbose_name = "Marksheet"
# verbose_name_plural = "Marksheets"
# unique_together = ("student", "course")
#
# def save(self, *args, **kwargs):
# percentage = (self.marks_obtained / self.total_marks) * 100
# if percentage >= 90:
# self.grade = "A+"
# elif percentage >= 80:
# self.grade = "A"
# elif percentage >= 70:
# self.grade = "B"
# elif percentage >= 60:
# self.grade = "C"
# elif percentage >= 50:
# self.grade = "D"
# else:
# self.grade = "F"
#
# super().save(*args, **kwargs)
#
# def __str__(self):
# return f"Marksheet: {self.student.first_name} {self.student.last_name}"
+5 -1
View File
@@ -4,5 +4,9 @@ from app import views
urlpatterns = [
path("dashboard", views.dashboard, name="dashboard"),
path("studentdashboard", views.studentdashboard, name="studentdashboard"),
path("marksheet", views.marksheet, name="marksheet"),
# path("marksheet", views.marksheet, name="marksheet"),
path('marksheet/<int:pk>/', views.view_marksheet, name='app_marksheet_view')
# path("course/manage", views.Add_Course, name="add_course"),
# path("course/edit/<int:id>", views.Edit_Course, name="edit_course"),
# path("course/delete/<int:id>", views.Delete_Course, name="delete_course"),
]
+79
View File
@@ -1,4 +1,5 @@
from django.shortcuts import render, redirect, get_object_or_404
from django.views.generic import DetailView
from django.contrib.admin import site
from app.models import (
Student,
@@ -12,6 +13,84 @@ from app.models import (
SubjectMark,
)
from django.contrib.auth.decorators import login_required
from django.contrib import messages
def view_marksheet(request, pk):
try:
marksheet = Marksheet.objects.get(pk=pk)
percentage = (
(marksheet.obtained_marks / marksheet.total_marks) * 100
if marksheet.total_marks > 0
else 0
)
context = {
"marksheet": marksheet,
"percentage": percentage,
"student": marksheet.student,
"school_name": "XYZ Secondary School",
"theory_max": 80,
"practical_max": 20,
"exam_year": marksheet.student.academic_year,
}
return render(request, "Hod/view_marksheet.html", context)
except Marksheet.DoesNotExist:
return HttpResponse("Marksheet not found", status=404)
@login_required
def Add_Course(request):
courses = Course.objects.all()
context = {
**site.each_context(request), # This adds admin context
"title": "Manage Courses",
"courses": courses,
"subtitle": "Course Management",
"site_title": "School Management",
"has_permission": True,
"is_popup": False,
"is_nav_sidebar_enabled": True,
"available_apps": site.get_app_list(request),
}
if request.method == "POST":
name = request.POST.get("name")
level = request.POST.get("level")
course_type = request.POST.get("course_type")
duration = request.POST.get("duration")
Course.objects.create(
name=name, level=level, course_type=course_type, duration=duration
)
messages.success(request, "Course Added Successfully!")
return redirect("add_course")
return render(request, "Hod/add_course.html", context)
@login_required
def Edit_Course(request, id):
course = Course.objects.all()
if request.method == "POST":
name = request.POST.get("name")
Course.objects.filter(id=id).update(
name=name,
)
messages.success(request, "Course Updated Successfully!")
return redirect("add_course")
context = {
"course": course,
}
return render(request, "Hod/add_course.html", context)
@login_required
def Delete_Course(request, id):
Course.objects.filter(id=id).delete()
messages.success(request, "Course Deleted Successfully")
return redirect("add_course")
@login_required