added admin pages and modified database

This commit is contained in:
Faraphel 2023-11-27 22:41:09 +01:00
parent 541cadaa3e
commit e99277f438
6 changed files with 78 additions and 95 deletions

4
.gitignore vendored
View file

@ -1,3 +1,3 @@
.idea/ .idea
venv/ venv
db.sqlite3 db.sqlite3

View file

@ -1,3 +1,56 @@
from django.contrib import admin from django.contrib import admin
from .models import Department, StudentGroup, TeachingUnit, StudentCard, TeachingSession, Attendance, Absence, \
AbsenceAttachment
# Register your models here. # Register your models here.
@admin.register(Department)
class AdminDepartment(admin.ModelAdmin):
list_display = ("id", "name")
search_fields = ("id", "name")
@admin.register(StudentGroup)
class AdminStudentGroup(admin.ModelAdmin):
list_display = ("id", "name")
search_fields = ("id", "name")
@admin.register(TeachingUnit)
class AdminTeachingUnit(admin.ModelAdmin):
list_display = ("id", "name")
search_fields = ("id", "name")
@admin.register(StudentCard)
class AdminStudentCard(admin.ModelAdmin):
list_display = ("id", "uid", "owner")
search_fields = ("id", "uid", "owner")
readonly_fields = ("uid",)
@admin.register(TeachingSession)
class AdminTeachingSession(admin.ModelAdmin):
list_display = ("id", "start", "end", "duration", "teacher")
search_fields = ("id", "start", "end", "duration", "teacher")
list_filter = ("start", "duration")
@admin.register(Attendance)
class AdminAttendance(admin.ModelAdmin):
list_display = ("id", "date", "student")
search_fields = ("id", "date", "student")
list_filter = ("date",)
@admin.register(Absence)
class AdminAbsence(admin.ModelAdmin):
list_display = ("id", "message", "student")
search_fields = ("id", "message", "student")
@admin.register(AbsenceAttachment)
class AdminAbsenceAttachment(admin.ModelAdmin):
list_display = ("id", "content", "absence")
search_fields = ("id", "content", "absence")

View file

@ -1,83 +0,0 @@
# Generated by Django 4.2.7 on 2023-11-27 10:56
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import uuid
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Absence',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('message', models.TextField()),
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='absent_sessions', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='TeachingUnit',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=32)),
('managers', models.ManyToManyField(related_name='managed_teaching_units', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='TeachingSession',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('start', models.DateTimeField()),
('duration', models.DurationField()),
('teacher', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='taught_sessions', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='StudentGroup',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=32)),
('students', models.ManyToManyField(related_name='student_groups', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='StudentCard',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('uid', models.BinaryField(max_length=7)),
('owner', models.ManyToManyField(related_name='student_cards', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Department',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=32)),
('managers', models.ManyToManyField(related_name='managed_departments', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Attendance',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('date', models.DateTimeField()),
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attended_sessions', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='AbsenceAttachment',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('content', models.FileField(upload_to='')),
('absence', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attachments', to='Palto.absence')),
],
),
]

View file

@ -2,10 +2,21 @@ import uuid
from datetime import datetime, timedelta from datetime import datetime, timedelta
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractUser
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class User(AbstractUser):
"""
A user.
Same as the base Django user, but the id is now an uuid instead of an int.
"""
id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36)
class Department(models.Model): class Department(models.Model):
""" """
A scholar department. A scholar department.
@ -17,9 +28,9 @@ class Department(models.Model):
id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36) id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36)
name: str = models.CharField(max_length=32) name: str = models.CharField(max_length=32)
managers = models.ManyToManyField(to=get_user_model(), related_name="managed_departments") managers = models.ManyToManyField(to=get_user_model(), blank=True, related_name="managing_departments")
teachers = models.ManyToManyField(to=get_user_model(), related_name="taught_departments") teachers = models.ManyToManyField(to=get_user_model(), blank=True, related_name="teaching_departments")
students = models.ManyToManyField(to=get_user_model(), related_name="study_departments") students = models.ManyToManyField(to=get_user_model(), blank=True, related_name="studying_departments")
class StudentGroup(models.Model): class StudentGroup(models.Model):
@ -35,7 +46,7 @@ class StudentGroup(models.Model):
id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36) id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36)
name: str = models.CharField(max_length=32) name: str = models.CharField(max_length=32)
students = models.ManyToManyField(to=get_user_model(), related_name="student_groups") students = models.ManyToManyField(to=get_user_model(), blank=True, related_name="student_groups")
class TeachingUnit(models.Model): class TeachingUnit(models.Model):
@ -51,7 +62,9 @@ class TeachingUnit(models.Model):
id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36) id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36)
name: str = models.CharField(max_length=32) name: str = models.CharField(max_length=32)
student_groups = models.ManyToManyField(to=StudentGroup, related_name="taught_units") managers = models.ManyToManyField(to=get_user_model(), blank=True, related_name="managing_units")
teachers = models.ManyToManyField(to=get_user_model(), blank=True, related_name="teaching_units")
student_groups = models.ManyToManyField(to=StudentGroup, blank=True, related_name="studying_units")
class StudentCard(models.Model): class StudentCard(models.Model):
@ -64,7 +77,7 @@ class StudentCard(models.Model):
id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36) id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36)
uid: bytes = models.BinaryField(max_length=7) uid: bytes = models.BinaryField(max_length=7)
owner = models.ManyToManyField(to=get_user_model(), related_name="student_cards") owner = models.ForeignKey(to=get_user_model(), on_delete=models.CASCADE, related_name="student_cards")
class TeachingSession(models.Model): class TeachingSession(models.Model):
@ -80,7 +93,7 @@ class TeachingSession(models.Model):
start: datetime = models.DateTimeField() start: datetime = models.DateTimeField()
duration: timedelta = models.DurationField() duration: timedelta = models.DurationField()
teacher = models.ForeignKey(to=get_user_model(), on_delete=models.CASCADE, related_name="taught_sessions") teacher = models.ForeignKey(to=get_user_model(), on_delete=models.CASCADE, related_name="teaching_sessions")
@property @property
def end(self) -> datetime: def end(self) -> datetime:
@ -97,7 +110,7 @@ class Attendance(models.Model):
id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36) id: uuid.UUID = models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False, max_length=36)
date: datetime = models.DateTimeField() date: datetime = models.DateTimeField()
student = models.ForeignKey(to=get_user_model(), on_delete=models.CASCADE, related_name="attended_sessions") student = models.ForeignKey(to=get_user_model(), on_delete=models.CASCADE, related_name="attending_sessions")
class Absence(models.Model): class Absence(models.Model):

View file

@ -148,5 +148,5 @@ REST_FRAMEWORK = {
] ]
} }
# User # User model
AUTH_USER_MODEL = "Palto.models.User" AUTH_USER_MODEL = "Palto.User"

View file