Attendance Management System Django With Source Code
The Attendance Management System Django is developed using Python Django, HTML,CSS, JavaScript and Bootstrap, This Django Attendance System contains the teacher side and the student side, the teacher can manage the attendance, marks and can generate the reports of the students, and the students can view their attendance, marks and the time table of their class schedule.
A College Management System Django built using Django framework. It is designed for interactions between students and teachers. Features include attendance, marks and time table.
This College Management System In Django with Attendance Management System Django also includes a downloadable Project With Source Code for free, just find the downloadable source code below and click to start downloading.
Watch the video here to see the full running College Management system with Attendance Management System in Django with Source Code.
To start creating a Attendance Management System Django, makes sure that you have PyCharm Professional IDE or any platform of django and its requirements Installed in your computer.
Reminders
To perform this python django project make sure that you have knowledge in the following:
- CSS
- HTML
- Javascript
- Database Management
Features Of This Attendance Management System Django
- Manage Students
- Manage Teachers
- Manage Attendance
- Manage Marks
- Manage Time Table
- Generate Reports
- Login/Logout System
In This Attendance Management System Django Consist Of The Following Method:
- CollegeERP – In this method which is the main method of the system.
- Info – In this method which is the main feature of the system.
Steps on how to create a Attendance Management System Django With Source Code
Attendance Management System Django With Source Code
- Step 1: Open file.
First , open “pycharm professional” after that click “file” and click “new project“.
- Step 2: Choose Django.
Second, after click “new project“, choose “Django” and click.
- Step 3: Select file location.
Third, select a file location wherever you want.
- Step 4: Create application name.
Fourth, name your application.
- Step 5: Click create.
Fifth, finish creating project by clicking “create” button.
- Step 6: Start of coding.
you are free to copy the following codes below in the given modules and method required.
The List Of Module Given Below Are Under The “College ERP” Method
- The Code Given Below Is For The “settings.py” Module – you can add the following code below into your “settings.py” under the “College ERP” method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
""" Django settings for erptest project. Generated by 'django-admin startproject' using Django 2.1.2. For more information on this file, see https://docs.djangoproject.com/en/2.1/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.1/ref/settings/ """ import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'jy8c-n9y=pf##!2^jae-l_5iafq6q%wfq8gdb6c0r5d52su+9y' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = ['*'] AUTH_USER_MODEL = 'info.User' # Application definition INSTALLED_APPS = [ 'info.apps.InfoConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'CollegeERP.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')] , 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] WSGI_APPLICATION = 'CollegeERP.wsgi.application' # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } # Password validation # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', }, { 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', }, { 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', }, { 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', }, ] # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_URL = '/static/' LOGIN_REDIRECT_URL = '/' |
In this module which is the settings under College ERP Method.
- The Code Given Below Is For The “urls.py” Module – you can add the following code below into your “urls.py” under the “College ERP” method.
1 2 3 4 5 6 7 8 9 10 11 12 |
from django.contrib import admin from django.urls import path, include from django.contrib.auth import views as auth_views urlpatterns = [ path('admin/', admin.site.urls), path('', include('info.urls')), path('info/', include('info.urls')), path('accounts/login/', auth_views.LoginView.as_view(template_name='info/login.html'), name='login'), path('accounts/logout/', auth_views.LogoutView.as_view(template_name='info/logout.html'), name='logout'), ] |
In this module which is the URL configuration module under College ERP method.
The List Of Module Given Below Are Under The “Info” Method
- The Code Given Below Is For The “views” Module – you can add the following code below into your “views” under the “Info” method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect from .models import Dept, Class, Student, Attendance, Course, Teacher, Assign, AttendanceTotal, time_slots, \ DAYS_OF_WEEK, AssignTime, AttendanceClass, StudentCourse, Marks, MarksClass from django.urls import reverse from django.utils import timezone from django.contrib.auth.decorators import login_required # Create your views here. @login_required def index(request): if request.user.is_teacher: return render(request, 'info/t_homepage.html') if request.user.is_student: return render(request, 'info/homepage.html') return render(request, 'info/logout.html') @login_required() def attendance(request, stud_id): stud = Student.objects.get(USN=stud_id) ass_list = Assign.objects.filter(class_id_id=stud.class_id) att_list = [] for ass in ass_list: try: a = AttendanceTotal.objects.get(student=stud, course=ass.course) except AttendanceTotal.DoesNotExist: a = AttendanceTotal(student=stud, course=ass.course) a.save() att_list.append(a) return render(request, 'info/attendance.html', {'att_list': att_list}) @login_required() def attendance_detail(request, stud_id, course_id): stud = get_object_or_404(Student, USN=stud_id) cr = get_object_or_404(Course, id=course_id) att_list = Attendance.objects.filter(course=cr, student=stud).order_by('date') return render(request, 'info/att_detail.html', {'att_list': att_list, 'cr': cr}) # Teacher Views @login_required def t_clas(request, teacher_id, choice): teacher1 = get_object_or_404(Teacher, id=teacher_id) return render(request, 'info/t_clas.html', {'teacher1': teacher1, 'choice': choice}) @login_required() def t_student(request, assign_id): ass = Assign.objects.get(id=assign_id) att_list = [] for stud in ass.class_id.student_set.all(): try: a = AttendanceTotal.objects.get(student=stud, course=ass.course) except AttendanceTotal.DoesNotExist: a = AttendanceTotal(student=stud, course=ass.course) a.save() att_list.append(a) return render(request, 'info/t_students.html', {'att_list': att_list}) @login_required() def t_class_date(request, assign_id): now = timezone.now() ass = get_object_or_404(Assign, id=assign_id) att_list = ass.attendanceclass_set.filter(date__lte=now).order_by('-date') return render(request, 'info/t_class_date.html', {'att_list': att_list}) @login_required() def cancel_class(request, ass_c_id): assc = get_object_or_404(AttendanceClass, id=ass_c_id) assc.status = 2 assc.save() return HttpResponseRedirect(reverse('t_class_date', args=(assc.assign_id,))) @login_required() def t_attendance(request, ass_c_id): assc = get_object_or_404(AttendanceClass, id=ass_c_id) ass = assc.assign c = ass.class_id context = { 'ass': ass, 'c': c, 'assc': assc, } return render(request, 'info/t_attendance.html', context) @login_required() def edit_att(request, ass_c_id): assc = get_object_or_404(AttendanceClass, id=ass_c_id) cr = assc.assign.course att_list = Attendance.objects.filter(attendanceclass=assc, course=cr) context = { 'assc': assc, 'att_list': att_list, } return render(request, 'info/t_edit_att.html', context) @login_required() def confirm(request, ass_c_id): assc = get_object_or_404(AttendanceClass, id=ass_c_id) ass = assc.assign cr = ass.course cl = ass.class_id for i, s in enumerate(cl.student_set.all()): status = request.POST[s.USN] if status == 'present': status = 'True' else: status = 'False' if assc.status == 1: try: a = Attendance.objects.get(course=cr, student=s, date=assc.date, attendanceclass=assc) a.status = status a.save() except Attendance.DoesNotExist: a = Attendance(course=cr, student=s, status=status, date=assc.date, attendanceclass=assc) a.save() else: a = Attendance(course=cr, student=s, status=status, date=assc.date, attendanceclass=assc) a.save() assc.status = 1 assc.save() return HttpResponseRedirect(reverse('t_class_date', args=(ass.id,))) @login_required() def t_attendance_detail(request, stud_id, course_id): stud = get_object_or_404(Student, USN=stud_id) cr = get_object_or_404(Course, id=course_id) att_list = Attendance.objects.filter(course=cr, student=stud).order_by('date') return render(request, 'info/t_att_detail.html', {'att_list': att_list, 'cr': cr}) @login_required() def change_att(request, att_id): a = get_object_or_404(Attendance, id=att_id) a.status = not a.status a.save() return HttpResponseRedirect(reverse('t_attendance_detail', args=(a.student.USN, a.course_id))) @login_required() def t_extra_class(request, assign_id): ass = get_object_or_404(Assign, id=assign_id) c = ass.class_id context = { 'ass': ass, 'c': c, } return render(request, 'info/t_extra_class.html', context) @login_required() def e_confirm(request, assign_id): ass = get_object_or_404(Assign, id=assign_id) cr = ass.course cl = ass.class_id assc = ass.attendanceclass_set.create(status=1, date=request.POST['date']) assc.save() for i, s in enumerate(cl.student_set.all()): status = request.POST[s.USN] if status == 'present': status = 'True' else: status = 'False' date = request.POST['date'] a = Attendance(course=cr, student=s, status=status, date=date, attendanceclass=assc) a.save() return HttpResponseRedirect(reverse('t_clas', args=(ass.teacher_id, 1))) @login_required() def t_report(request, assign_id): ass = get_object_or_404(Assign, id=assign_id) sc_list = [] for stud in ass.class_id.student_set.all(): a = StudentCourse.objects.get(student=stud, course=ass.course) sc_list.append(a) return render(request, 'info/t_report.html', {'sc_list': sc_list}) @login_required() def timetable(request, class_id): asst = AssignTime.objects.filter(assign__class_id=class_id) matrix = [['' for i in range(12)] for j in range(6)] for i, d in enumerate(DAYS_OF_WEEK): t = 0 for j in range(12): if j == 0: matrix[i][0] = d[0] continue if j == 4 or j == 8: continue try: a = asst.get(period=time_slots[t][0], day=d[0]) matrix[i][j] = a.assign.course_id except AssignTime.DoesNotExist: pass t += 1 context = {'matrix': matrix} return render(request, 'info/timetable.html', context) @login_required() def t_timetable(request, teacher_id): asst = AssignTime.objects.filter(assign__teacher_id=teacher_id) class_matrix = [[True for i in range(12)] for j in range(6)] for i, d in enumerate(DAYS_OF_WEEK): t = 0 for j in range(12): if j == 0: class_matrix[i][0] = d[0] continue if j == 4 or j == 8: continue try: a = asst.get(period=time_slots[t][0], day=d[0]) class_matrix[i][j] = a except AssignTime.DoesNotExist: pass t += 1 context = { 'class_matrix': class_matrix, } return render(request, 'info/t_timetable.html', context) @login_required() def free_teachers(request, asst_id): asst = get_object_or_404(AssignTime, id=asst_id) ft_list = [] t_list = Teacher.objects.filter(assign__class_id__id=asst.assign.class_id_id) for t in t_list: at_list = AssignTime.objects.filter(assign__teacher=t) if not any([True if at.period == asst.period and at.day == asst.day else False for at in at_list]): ft_list.append(t) return render(request, 'info/free_teachers.html', {'ft_list': ft_list}) # student marks @login_required() def marks_list(request, stud_id): stud = Student.objects.get(USN=stud_id, ) ass_list = Assign.objects.filter(class_id_id=stud.class_id) sc_list = [] for ass in ass_list: try: sc = StudentCourse.objects.get(student=stud, course=ass.course) except StudentCourse.DoesNotExist: sc = StudentCourse(student=stud, course=ass.course) sc.save() sc.marks_set.create(type='I', name='Internal test 1') sc.marks_set.create(type='I', name='Internal test 2') sc.marks_set.create(type='I', name='Internal test 3') sc.marks_set.create(type='E', name='Event 1') sc.marks_set.create(type='E', name='Event 2') sc.marks_set.create(type='S', name='Semester End Exam') sc_list.append(sc) return render(request, 'info/marks_list.html', {'sc_list': sc_list}) # teacher marks @login_required() def t_marks_list(request, assign_id): ass = get_object_or_404(Assign, id=assign_id) m_list = MarksClass.objects.filter(assign=ass) return render(request, 'info/t_marks_list.html', {'m_list': m_list}) @login_required() def t_marks_entry(request, marks_c_id): mc = get_object_or_404(MarksClass, id=marks_c_id) ass = mc.assign c = ass.class_id context = { 'ass': ass, 'c': c, 'mc': mc, } return render(request, 'info/t_marks_entry.html', context) @login_required() def marks_confirm(request, marks_c_id): mc = get_object_or_404(MarksClass, id=marks_c_id) ass = mc.assign cr = ass.course cl = ass.class_id for s in cl.student_set.all(): mark = request.POST[s.USN] sc = StudentCourse.objects.get(course=cr, student=s) m = sc.marks_set.get(name=mc.name) m.marks1 = mark m.save() mc.status = True mc.save() return HttpResponseRedirect(reverse('t_marks_list', args=(ass.id,))) @login_required() def edit_marks(request, marks_c_id): mc = get_object_or_404(MarksClass, id=marks_c_id) cr = mc.assign.course stud_list = mc.assign.class_id.student_set.all() m_list = [] for stud in stud_list: sc = StudentCourse.objects.get(course=cr, student=stud) m = sc.marks_set.get(name=mc.name) m_list.append(m) context = { 'mc': mc, 'm_list': m_list, } return render(request, 'info/edit_marks.html', context) @login_required() def student_marks(request, assign_id): ass = Assign.objects.get(id=assign_id) sc_list = StudentCourse.objects.filter(student__in=ass.class_id.student_set.all(), course=ass.course) return render(request, 'info/t_student_marks.html', {'sc_list': sc_list}) |
In this module which is the index module of the Info method.
- The Code Given Below Is For The “urls.py” Module – you can add the following code below into your “urls.py” under the “Info” method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from django.urls import path from . import views urlpatterns = [ path('', views.index, name='index'), path('student/<slug:stud_id>/attendance/', views.attendance, name='attendance'), path('student/<slug:stud_id>/<slug:course_id>/attendance/', views.attendance_detail, name='attendance_detail'), path('student/<slug:class_id>/timetable/', views.timetable, name='timetable'), # path('student/<slug:class_id>/search/', views.student_search, name='student_search'), path('student/<slug:stud_id>/marks_list/', views.marks_list, name='marks_list'), path('teacher/<slug:teacher_id>/<int:choice>/Classes/', views.t_clas, name='t_clas'), path('teacher/<int:assign_id>/Students/attendance/', views.t_student, name='t_student'), path('teacher/<int:assign_id>/ClassDates/', views.t_class_date, name='t_class_date'), path('teacher/<int:ass_c_id>/Cancel/', views.cancel_class, name='cancel_class'), path('teacher/<int:ass_c_id>/attendance/', views.t_attendance, name='t_attendance'), path('teacher/<int:ass_c_id>/Edit_att/', views.edit_att, name='edit_att'), path('teacher/<int:ass_c_id>/attendance/confirm/', views.confirm, name='confirm'), path('teacher/<slug:stud_id>/<slug:course_id>/attendance/', views.t_attendance_detail, name='t_attendance_detail'), path('teacher/<int:att_id>/change_attendance/', views.change_att, name='change_att'), path('teacher/<int:assign_id>/Extra_class/', views.t_extra_class, name='t_extra_class'), path('teacher/<slug:assign_id>/Extra_class/confirm/', views.e_confirm, name='e_confirm'), path('teacher/<int:assign_id>/Report/', views.t_report, name='t_report'), path('teacher/<slug:teacher_id>/t_timetable/', views.t_timetable, name='t_timetable'), path('teacher/<int:asst_id>/Free_teachers/', views.free_teachers, name='free_teachers'), path('teacher/<int:assign_id>/marks_list/', views.t_marks_list, name='t_marks_list'), path('teacher/<int:assign_id>/Students/Marks/', views.student_marks, name='t_student_marks'), path('teacher/<int:marks_c_id>/marks_entry/', views.t_marks_entry, name='t_marks_entry'), path('teacher/<int:marks_c_id>/marks_entry/confirm/', views.marks_confirm, name='marks_confirm'), path('teacher/<int:marks_c_id>/Edit_marks/', views.edit_marks, name='edit_marks'), ] |
In this module which is the URL configuration module under Info method.
- The Code Given Below Is For The “models.py” Module – you can add the following code below into your “models.py” under the “Info” method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
from django.db import models import math from django.core.validators import MinValueValidator, MaxValueValidator from django.contrib.auth.models import AbstractUser from django.db.models.signals import post_save, post_delete from datetime import timedelta # Create your models here. sex_choice = ( ('Male', 'Male'), ('Female', 'Female') ) time_slots = ( ('7:30 - 8:30', '7:30 - 8:30'), ('8:30 - 9:30', '8:30 - 9:30'), ('9:30 - 10:30', '9:30 - 10:30'), ('11:00 - 11:50', '11:00 - 11:50'), ('11:50 - 12:40', '11:50 - 12:40'), ('12:40 - 1:30', '12:40 - 1:30'), ('2:30 - 3:30', '2:30 - 3:30'), ('3:30 - 4:30', '3:30 - 4:30'), ('4:30 - 5:30', '4:30 - 5:30'), ) DAYS_OF_WEEK = ( ('Monday', 'Monday'), ('Tuesday', 'Tuesday'), ('Wednesday', 'Wednesday'), ('Thursday', 'Thursday'), ('Friday', 'Friday'), ('Saturday', 'Saturday'), ) test_name = ( ('Internal test 1', 'Internal test 1'), ('Internal test 2', 'Internal test 2'), ('Internal test 3', 'Internal test 3'), ('Event 1', 'Event 1'), ('Event 2', 'Event 2'), ('Semester End Exam', 'Semester End Exam'), ) class User(AbstractUser): @property def is_student(self): if hasattr(self, 'student'): return True return False @property def is_teacher(self): if hasattr(self, 'teacher'): return True return False class Dept(models.Model): id = models.CharField(primary_key='True', max_length=100) name = models.CharField(max_length=200) def __str__(self): return self.name class Course(models.Model): dept = models.ForeignKey(Dept, on_delete=models.CASCADE) id = models.CharField(primary_key='True', max_length=50) name = models.CharField(max_length=50) shortname = models.CharField(max_length=50, default='X') def __str__(self): return self.name class Class(models.Model): # courses = models.ManyToManyField(Course, default=1) id = models.CharField(primary_key='True', max_length=100) dept = models.ForeignKey(Dept, on_delete=models.CASCADE) section = models.CharField(max_length=100) sem = models.IntegerField() class Meta: verbose_name_plural = 'classes' def __str__(self): d = Dept.objects.get(name=self.dept) return '%s : %d %s' % (d.name, self.sem, self.section) class Student(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, null=True) class_id = models.ForeignKey(Class, on_delete=models.CASCADE, default=1) USN = models.CharField(primary_key='True', max_length=100) name = models.CharField(max_length=200) sex = models.CharField(max_length=50, choices=sex_choice, default='Male') DOB = models.DateField(default='1998-01-01') def __str__(self): return self.name class Teacher(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, null=True) id = models.CharField(primary_key=True, max_length=100) dept = models.ForeignKey(Dept, on_delete=models.CASCADE, default=1) name = models.CharField(max_length=100) sex = models.CharField(max_length=50, choices=sex_choice, default='Male') DOB = models.DateField(default='1980-01-01') def __str__(self): return self.name class Assign(models.Model): class_id = models.ForeignKey(Class, on_delete=models.CASCADE) course = models.ForeignKey(Course, on_delete=models.CASCADE) teacher = models.ForeignKey(Teacher, on_delete=models.CASCADE) class Meta: unique_together = (('course', 'class_id', 'teacher'),) def __str__(self): cl = Class.objects.get(id=self.class_id_id) cr = Course.objects.get(id=self.course_id) te = Teacher.objects.get(id=self.teacher_id) return '%s : %s : %s' % (te.name, cr.shortname, cl) class AssignTime(models.Model): assign = models.ForeignKey(Assign, on_delete=models.CASCADE) period = models.CharField(max_length=50, choices=time_slots, default='11:00 - 11:50') day = models.CharField(max_length=15, choices=DAYS_OF_WEEK) class AttendanceClass(models.Model): assign = models.ForeignKey(Assign, on_delete=models.CASCADE) date = models.DateField() status = models.IntegerField(default=0) class Meta: verbose_name = 'Attendance' verbose_name_plural = 'Attendance' class Attendance(models.Model): course = models.ForeignKey(Course, on_delete=models.CASCADE) student = models.ForeignKey(Student, on_delete=models.CASCADE) attendanceclass = models.ForeignKey(AttendanceClass, on_delete=models.CASCADE, default=1) date = models.DateField(default='2018-10-23') status = models.BooleanField(default='True') def __str__(self): sname = Student.objects.get(name=self.student) cname = Course.objects.get(name=self.course) return '%s : %s' % (sname.name, cname.shortname) class AttendanceTotal(models.Model): course = models.ForeignKey(Course, on_delete=models.CASCADE) student = models.ForeignKey(Student, on_delete=models.CASCADE) class Meta: unique_together = (('student', 'course'),) @property def att_class(self): stud = Student.objects.get(name=self.student) cr = Course.objects.get(name=self.course) att_class = Attendance.objects.filter(course=cr, student=stud, status='True').count() return att_class @property def total_class(self): stud = Student.objects.get(name=self.student) cr = Course.objects.get(name=self.course) total_class = Attendance.objects.filter(course=cr, student=stud).count() return total_class @property def attendance(self): stud = Student.objects.get(name=self.student) cr = Course.objects.get(name=self.course) total_class = Attendance.objects.filter(course=cr, student=stud).count() att_class = Attendance.objects.filter(course=cr, student=stud, status='True').count() if total_class == 0: attendance = 0 else: attendance = round(att_class / total_class * 100, 2) return attendance @property def classes_to_attend(self): stud = Student.objects.get(name=self.student) cr = Course.objects.get(name=self.course) total_class = Attendance.objects.filter(course=cr, student=stud).count() att_class = Attendance.objects.filter(course=cr, student=stud, status='True').count() cta = math.ceil((0.75 * total_class - att_class) / 0.25) if cta < 0: return 0 return cta class StudentCourse(models.Model): student = models.ForeignKey(Student, on_delete=models.CASCADE) course = models.ForeignKey(Course, on_delete=models.CASCADE) class Meta: unique_together = (('student', 'course'),) verbose_name_plural = 'Marks' def __str__(self): sname = Student.objects.get(name=self.student) cname = Course.objects.get(name=self.course) return '%s : %s' % (sname.name, cname.shortname) def get_cie(self): marks_list = self.marks_set.all() m = [] for mk in marks_list: m.append(mk.marks1) cie = math.ceil(sum(m[:5]) / 2) return cie def get_attendance(self): a = AttendanceTotal.objects.get(student=self.student, course=self.course) return a.attendance class Marks(models.Model): studentcourse = models.ForeignKey(StudentCourse, on_delete=models.CASCADE) name = models.CharField(max_length=50, choices=test_name, default='Internal test 1') marks1 = models.IntegerField(default=0, validators=[MinValueValidator(0), MaxValueValidator(100)]) class Meta: unique_together = (('studentcourse', 'name'),) @property def total_marks(self): if self.name == 'Semester End Exam': return 100 return 20 class MarksClass(models.Model): assign = models.ForeignKey(Assign, on_delete=models.CASCADE) name = models.CharField(max_length=50, choices=test_name, default='Internal test 1') status = models.BooleanField(default='False') class Meta: unique_together = (('assign', 'name'),) @property def total_marks(self): if self.name == 'Semester End Exam': return 100 return 20 class AttendanceRange(models.Model): start_date = models.DateField() end_date = models.DateField() # Triggers def daterange(start_date, end_date): for n in range(int((end_date - start_date).days)): yield start_date + timedelta(n) days = { 'Monday': 1, 'Tuesday': 2, 'Wednesday': 3, 'Thursday': 4, 'Friday': 5, 'Saturday': 6, } def create_attendance(sender, instance, **kwargs): if kwargs['created']: start_date = AttendanceRange.objects.all()[:1].get().start_date end_date = AttendanceRange.objects.all()[:1].get().end_date for single_date in daterange(start_date, end_date): if single_date.isoweekday() == days[instance.day]: try: AttendanceClass.objects.get(date=single_date.strftime("%Y-%m-%d"), assign=instance.assign) except AttendanceClass.DoesNotExist: a = AttendanceClass(date=single_date.strftime("%Y-%m-%d"), assign=instance.assign) a.save() def create_marks(sender, instance, **kwargs): if kwargs['created']: if hasattr(instance, 'name'): ass_list = instance.class_id.assign_set.all() for ass in ass_list: try: StudentCourse.objects.get(student=instance, course=ass.course) except StudentCourse.DoesNotExist: sc = StudentCourse(student=instance, course=ass.course) sc.save() sc.marks_set.create(name='Internal test 1') sc.marks_set.create(name='Internal test 2') sc.marks_set.create(name='Internal test 3') sc.marks_set.create(name='Event 1') sc.marks_set.create(name='Event 2') sc.marks_set.create(name='Semester End Exam') elif hasattr(instance, 'course'): stud_list = instance.class_id.student_set.all() cr = instance.course for s in stud_list: try: StudentCourse.objects.get(student=s, course=cr) except StudentCourse.DoesNotExist: sc = StudentCourse(student=s, course=cr) sc.save() sc.marks_set.create(name='Internal test 1') sc.marks_set.create(name='Internal test 2') sc.marks_set.create(name='Internal test 3') sc.marks_set.create(name='Event 1') sc.marks_set.create(name='Event 2') sc.marks_set.create(name='Semester End Exam') def create_marks_class(sender, instance, **kwargs): if kwargs['created']: for name in test_name: try: MarksClass.objects.get(assign=instance, name=name[0]) except MarksClass.DoesNotExist: m = MarksClass(assign=instance, name=name[0]) m.save() def delete_marks(sender, instance, **kwargs): stud_list = instance.class_id.student_set.all() StudentCourse.objects.filter(course=instance.course, student__in=stud_list).delete() post_save.connect(create_marks, sender=Student) post_save.connect(create_marks, sender=Assign) post_save.connect(create_marks_class, sender=Assign) post_save.connect(create_attendance, sender=AssignTime) post_delete.connect(delete_marks, sender=Assign) |
In this module which you can found classes to be call under Info method.
I have here the list of Best Python Project with Source code free to download for free, I hope this can help you a lot.
Run Quick Virus Scan for secure Download
Run Quick Scan for secure DownloadDownloadable Source Code Below.
Teacher Username: AngelJudeSuarez
Teacher Password: project123
Student Username: AdrianMercurio
Student Password: project123
Anyway, if you want to level up your programming knowledge, especially python, try this new article I’ve made for you Best Python Projects with source code for Beginners. But If you’re going to focus on web development using Django, you can download here from our list of Best Django Projects with source code based on real-world projects.
How To Run The Attendance Management System Django?
Step 1: Extract/unzip the file
Step 2: Go inside the project folder, open cmd and type the following commands to install Django Framework and run the webserver:
1.) pip install -r requirements.txt
2.) python manage.py runserver
Step 3: Finally, open the browser and go to localhost:8000

Summary
The system is built fully in Django Framework in back-end and HTML, CSS in front-end. It has full-featured user interface with all the functionalities
This Article is the way to enhance and develop our skills and logic ideas which is important in practicing the python programming language which is most well known and most usable programming language in many company.
Related article below
- How To Make A Point Of Sale System In Python
- Best Python Projects for Beginners
- Python MySQL Connection: Simple Python Step by Step Guide
- Python PIP Command Set-up / Fix: Step by Step Guide
- Random Password Generator in Python Projects With Source Code 2020
- Python Range Function|Range in Python Explained with Examples 2020
Inquiries
If you have any questions or suggestions about Attendance Management System Django, please feel free to leave a comment below.