Commit a536d1db authored by Alvin Joshua Andrada's avatar Alvin Joshua Andrada

everything done except linking to course and date time formatting

parent eb1ef2f3
from django.contrib import admin
from .models import Event, Location
class EventInline(admin.TabularInline):
model = Event
class EventAdmin(admin.ModelAdmin):
model = Event
class LocationAdmin(admin.ModelAdmin):
model = Location
#Shows all events that occur at the same location
inlines = [EventInline,]
admin.site.register(Event, EventAdmin)
admin.site.register(Location, LocationAdmin)
from django.apps import AppConfig
class CalendarAppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'calendar_app'
# Generated by Django 4.1.7 on 2023-03-02 17:46
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Location',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('mode', models.CharField(choices=[('onsite', 'onsite'), ('online', 'online'), ('hybrid', 'hybrid')], default='onsite', max_length=6)),
('venue', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('target_datetime', models.DateTimeField()),
('activity', models.CharField(max_length=100)),
('estimated_hours', models.FloatField()),
('location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='calendar_app.location')),
],
),
]
from django.db import models
# from Assignments.models import Course
class Event(models.Model):
target_datetime = models.DateTimeField()
activity = models.CharField(max_length=100)
estimated_hours = models.FloatField()
location = models.ForeignKey(
'Location',
on_delete = models.CASCADE,
)
# course = models.ForeignKey(
# 'Assignments.Course',
# on_delete = models.CASCADE,
# )
def __str__(self):
return '{} on {}'.format(self.activity, self.target_datetime)
class Location(models.Model):
mode_choices = [
('onsite','onsite'),
('online','online'),
('hybrid','hybrid'),
]
mode = models.CharField(
max_length=6,
choices=mode_choices,
default='onsite',
)
venue = models.CharField(max_length=200)
def __str__(self):
return self.venue
from django.test import TestCase
# Create your tests here.
#calendar_app/urls
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "calendar_app"
#Reference: Queries - Django Documentation
# https://docs.djangoproject.com/en/4.1/topics/db/queries/#retrieving-a-single-object-with-get
from django.shortcuts import render
from django.http import HttpResponse
from .models import Event, Location
def index(request):
total_objects = Event.objects.count()
page_format = "Widget's Calendar of Activities <br>"
#displays the details for each events
for i in range(1,total_objects+1):
page_format += '<br>' + display_details(i)
return HttpResponse(page_format)
def display_details(index):
#gets all the object's attributes
event = Event.objects.get(pk=index)
date_time = event.target_datetime
activity = event.activity
estimated_hours = event.estimated_hours
# course_code = event.course.code
# course_title = event.course.title
# section = event.course.section
mode = event.location.mode
venue = event.location.venue
#arrange all the details
display = 'Date and Time: {} <br>'.format(date_time)
display += 'Activity: {} <br>'.format(activity)
display += 'Estimated Hours {} <br>'.format(estimated_hours)
display += 'Course/Section: {} {}-{} <br>' #.format(course_code,course_title,section)
display += 'Mode: {} <br>'.format(mode)
display += 'Venue: {} <br>'.format(venue)
return display
\ No newline at end of file
...@@ -37,6 +37,7 @@ INSTALLED_APPS = [ ...@@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'calendar_app',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -14,8 +14,9 @@ Including another URLconf ...@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('calendar/', include('calendar_app.urls', namespace="calendar_app"))
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment