Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project is done #59

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.9-alpine
ENV PYTHONUNBUFFERED 1

WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD python manage.py runserver 0.0.0.0:80
Binary file added db.sqlite3
Binary file not shown.
Empty file modified manage.py
100755 → 100644
Empty file.
6 changes: 4 additions & 2 deletions myproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

import os

# Defauly AUTO Field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand All @@ -27,8 +30,7 @@
DEBUG = True

# <HINT> add your cloud host here
ALLOWED_HOSTS = []

ALLOWED_HOSTS = ['final-cloud-app-with-database-imq6imauja-uc.a.run.app']

# Application definition
INSTALLED_APPS = [
Expand Down
2 changes: 1 addition & 1 deletion myproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

urlpatterns = [
path('admin/', admin.site.urls),
path('onlinecourse/', include('onlinecourse.urls')),
path('', include('onlinecourse.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
32 changes: 23 additions & 9 deletions onlinecourse/admin.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
from django.contrib import admin
# <HINT> Import any new Models here
from .models import Course, Lesson, Instructor, Learner

# <HINT> Register QuestionInline and ChoiceInline classes here
from .models import Course, Lesson, Instructor, Learner, Question, Choice


class ChoiceInline(admin.TabularInline):
model = Choice
extra = 3


class LessonInline(admin.StackedInline):
model = Lesson
extra = 5


# Register your models here.
class CourseAdmin(admin.ModelAdmin):
inlines = [LessonInline]
list_display = ('name', 'pub_date')
list_filter = ['pub_date']
search_fields = ['name', 'description']
list_display = ("name", "pub_date")
list_filter = ["pub_date"]
search_fields = ["name", "description"]


class LessonAdmin(admin.ModelAdmin):
list_display = ['title']
list_display = ["title"]


class QuestionAdmin(admin.ModelAdmin):
list_display = ("question_text", "grade", "course")
list_filter = ("course",)
search_fields = ("question_text",)
inlines = [ChoiceInline]


class ChoiceAdmin(admin.ModelAdmin):
list_display = ("choice_text", "is_correct")
list_filter = ("question",)

# <HINT> Register Question and Choice models here

admin.site.register(Course, CourseAdmin)
admin.site.register(Lesson, LessonAdmin)
admin.site.register(Question, QuestionAdmin)
admin.site.register(Choice, ChoiceAdmin)
admin.site.register(Instructor)
admin.site.register(Learner)
108 changes: 108 additions & 0 deletions onlinecourse/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Generated by Django 3.1.3 on 2023-09-01 08:13

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Choice',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('choice_text', models.CharField(default='choice', max_length=200)),
('is_correct', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='Course',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(default='online course', max_length=30)),
('image', models.ImageField(upload_to='course_images/')),
('description', models.CharField(max_length=1000)),
('pub_date', models.DateField(null=True)),
('total_enrollment', models.IntegerField(default=0)),
],
),
migrations.CreateModel(
name='Enrollment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date_enrolled', models.DateField(default=django.utils.timezone.now)),
('mode', models.CharField(choices=[('audit', 'Audit'), ('honor', 'Honor'), ('BETA', 'BETA')], default='audit', max_length=5)),
('rating', models.FloatField(default=5.0)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='onlinecourse.course')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Submission',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('choices', models.ManyToManyField(to='onlinecourse.Choice')),
('enrollment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='onlinecourse.enrollment')),
],
),
migrations.CreateModel(
name='Question',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('question_text', models.CharField(default='question', max_length=200)),
('grade', models.IntegerField(default=0)),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='onlinecourse.course')),
],
),
migrations.CreateModel(
name='Lesson',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(default='title', max_length=200)),
('order', models.IntegerField(default=0)),
('content', models.TextField()),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='onlinecourse.course')),
],
),
migrations.CreateModel(
name='Learner',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('occupation', models.CharField(choices=[('student', 'Student'), ('developer', 'Developer'), ('data_scientist', 'Data Scientist'), ('dba', 'Database Admin')], default='student', max_length=20)),
('social_link', models.URLField()),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Instructor',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('full_time', models.BooleanField(default=True)),
('total_learners', models.IntegerField()),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='course',
name='instructors',
field=models.ManyToManyField(to='onlinecourse.Instructor'),
),
migrations.AddField(
model_name='course',
name='users',
field=models.ManyToManyField(through='onlinecourse.Enrollment', to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='choice',
name='question',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='onlinecourse.question'),
),
]
23 changes: 23 additions & 0 deletions onlinecourse/migrations/0002_auto_20230901_0926.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.1.3 on 2023-09-01 09:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('onlinecourse', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='choice',
name='choice_text',
field=models.CharField(max_length=200),
),
migrations.AlterField(
model_name='question',
name='question_text',
field=models.CharField(max_length=200),
),
]
113 changes: 47 additions & 66 deletions onlinecourse/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from django.utils.timezone import now

try:
from django.db import models
except Exception:
Expand Down Expand Up @@ -29,43 +30,38 @@ class Learner(models.Model):
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
)
STUDENT = 'student'
DEVELOPER = 'developer'
DATA_SCIENTIST = 'data_scientist'
DATABASE_ADMIN = 'dba'
STUDENT = "student"
DEVELOPER = "developer"
DATA_SCIENTIST = "data_scientist"
DATABASE_ADMIN = "dba"
OCCUPATION_CHOICES = [
(STUDENT, 'Student'),
(DEVELOPER, 'Developer'),
(DATA_SCIENTIST, 'Data Scientist'),
(DATABASE_ADMIN, 'Database Admin')
(STUDENT, "Student"),
(DEVELOPER, "Developer"),
(DATA_SCIENTIST, "Data Scientist"),
(DATABASE_ADMIN, "Database Admin"),
]
occupation = models.CharField(
null=False,
max_length=20,
choices=OCCUPATION_CHOICES,
default=STUDENT
null=False, max_length=20, choices=OCCUPATION_CHOICES, default=STUDENT
)
social_link = models.URLField(max_length=200)

def __str__(self):
return self.user.username + "," + \
self.occupation
return self.user.username + "," + self.occupation


# Course model
class Course(models.Model):
name = models.CharField(null=False, max_length=30, default='online course')
image = models.ImageField(upload_to='course_images/')
name = models.CharField(null=False, max_length=30, default="online course")
image = models.ImageField(upload_to="course_images/")
description = models.CharField(max_length=1000)
pub_date = models.DateField(null=True)
instructors = models.ManyToManyField(Instructor)
users = models.ManyToManyField(settings.AUTH_USER_MODEL, through='Enrollment')
users = models.ManyToManyField(settings.AUTH_USER_MODEL, through="Enrollment")
total_enrollment = models.IntegerField(default=0)
is_enrolled = False

def __str__(self):
return "Name: " + self.name + "," + \
"Description: " + self.description
return "Name: " + self.name + "," + "Description: " + self.description


# Lesson model
Expand All @@ -77,58 +73,43 @@ class Lesson(models.Model):


# Enrollment model
# <HINT> Once a user enrolled a class, an enrollment entry should be created between the user and course
# And we could use the enrollment to track information such as exam submissions
class Enrollment(models.Model):
AUDIT = 'audit'
HONOR = 'honor'
BETA = 'BETA'
COURSE_MODES = [
(AUDIT, 'Audit'),
(HONOR, 'Honor'),
(BETA, 'BETA')
]
AUDIT = "audit"
HONOR = "honor"
BETA = "BETA"
COURSE_MODES = [(AUDIT, "Audit"), (HONOR, "Honor"), (BETA, "BETA")]
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
course = models.ForeignKey(Course, on_delete=models.CASCADE)
date_enrolled = models.DateField(default=now)
mode = models.CharField(max_length=5, choices=COURSE_MODES, default=AUDIT)
rating = models.FloatField(default=5.0)


# <HINT> Create a Question Model with:
# Used to persist question content for a course
# Has a One-To-Many (or Many-To-Many if you want to reuse questions) relationship with course
# Has a grade point for each question
# Has question content
# Other fields and methods you would like to design
#class Question(models.Model):
# Foreign key to lesson
# question text
# question grade/mark

# <HINT> A sample model method to calculate if learner get the score of the question
#def is_get_score(self, selected_ids):
# all_answers = self.choice_set.filter(is_correct=True).count()
# selected_correct = self.choice_set.filter(is_correct=True, id__in=selected_ids).count()
# if all_answers == selected_correct:
# return True
# else:
# return False


# <HINT> Create a Choice Model with:
# Used to persist choice content for a question
# One-To-Many (or Many-To-Many if you want to reuse choices) relationship with Question
# Choice content
# Indicate if this choice of the question is a correct one or not
# Other fields and methods you would like to design
# class Choice(models.Model):

# <HINT> The submission model
# One enrollment could have multiple submission
# One submission could have multiple choices
# One choice could belong to multiple submissions
#class Submission(models.Model):
# enrollment = models.ForeignKey(Enrollment, on_delete=models.CASCADE)
# choices = models.ManyToManyField(Choice)
# Other fields and methods you would like to design
# Question model
class Question(models.Model):
course = models.ForeignKey(Course, on_delete=models.CASCADE)
question_text = models.CharField(max_length=200)
grade = models.IntegerField(default=0)

def is_get_score(self, selected_ids):
all_answers = self.choice_set.filter(is_correct=True).count()
selected_correct = self.choice_set.filter(
is_correct=True, id__in=selected_ids
).count()
if all_answers == selected_correct:
return True
else:
return False


# Choice model
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
is_correct = models.BooleanField(default=False)


# Submission model
class Submission(models.Model):
enrollment = models.ForeignKey(Enrollment, on_delete=models.CASCADE)
choices = models.ManyToManyField(Choice)
Loading