Skip to content

Commit

Permalink
simple works
Browse files Browse the repository at this point in the history
  • Loading branch information
that-ar-guy committed Dec 30, 2024
1 parent 02ab6bb commit 3d44c44
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 4 deletions.
19 changes: 18 additions & 1 deletion backend/planner/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
from django.contrib import admin
from .models import Exam, Subject, Unit

# Register your models here.
class UnitInline(admin.TabularInline):
model = Unit
extra = 1 # Show one extra blank field for new Unit entries


class SubjectAdmin(admin.ModelAdmin):
inlines = [UnitInline] # Allows adding Units directly within the Subject admin
list_display = ('name', 'priority', 'exam_date', 'exam') # Display relevant fields


class ExamAdmin(admin.ModelAdmin):
list_display = ('name', 'date') # Display relevant fields


admin.site.register(Exam, ExamAdmin)
admin.site.register(Subject, SubjectAdmin)
admin.site.register(Unit)
79 changes: 79 additions & 0 deletions backend/planner/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Generated by Django 5.1.4 on 2024-12-30 06:25

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Exam",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=100)),
("date", models.DateField()),
],
),
migrations.CreateModel(
name="Subject",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=100)),
("priority", models.IntegerField()),
("exam_date", models.DateField()),
(
"exam",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="subjects",
to="planner.exam",
),
),
],
),
migrations.CreateModel(
name="Unit",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=100)),
("is_completed", models.BooleanField(default=False)),
(
"subject",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="units",
to="planner.subject",
),
),
],
),
]
25 changes: 25 additions & 0 deletions backend/planner/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
from django.db import models

# Create your models here.
class Exam(models.Model):
name = models.CharField(max_length=100) # Exam name (e.g., Midterms, Finals)
date = models.DateField() # Overall exam date

def __str__(self):
return self.name


class Subject(models.Model):
exam = models.ForeignKey(Exam, on_delete=models.CASCADE, related_name='subjects')
name = models.CharField(max_length=100) # Subject name
priority = models.IntegerField() # Subject priority (e.g., 1 = High, 2 = Medium, etc.)
exam_date = models.DateField() # Subject-specific exam date

def __str__(self):
return f"{self.name} (Priority: {self.priority})"


class Unit(models.Model):
subject = models.ForeignKey(Subject, on_delete=models.CASCADE, related_name='units')
name = models.CharField(max_length=100) # Unit name
is_completed = models.BooleanField(default=False) # Completion status for tracking progress

def __str__(self):
return f"{self.name} ({'Completed' if self.is_completed else 'Pending'})"
15 changes: 15 additions & 0 deletions backend/planner/templates/planner/welcome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>StudySphere</title>
</head>
<body>
<h1>Welcome to StudySphere</h1>
<h2>Subjects:</h2>
<ul>
{% for subject in subjects %}
<li>{{ subject.name }} (Priority: {{ subject.priority }})</li>
{% endfor %}
</ul>
</body>
</html>
6 changes: 3 additions & 3 deletions backend/planner/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.shortcuts import render
from django.http import HttpResponse

from .models import Subject
# Create your views here.

def welcome(request):
return HttpResponse("<h1>Welcome to StudySphere!</h1>")
subjects = Subject.objects.all()
return render(request, 'planner/welcome.html', {'subjects': subjects})

0 comments on commit 3d44c44

Please sign in to comment.