Commit 67e11a16 authored by Mariam Garsin's avatar Mariam Garsin

Adding the calendar app

parent 3f848129
No preview for this file type
from django.contrib import admin from django.contrib import admin
# Register your models here. from.models import Event, Location
class EventAdmin(admin.ModelAdmin):
model = Event
class LocationAdmin(admin.ModelAdmin):
model = Location
admin.site.register(Event, EventAdmin)
admin.site.register(Location, LocationAdmin)
\ No newline at end of file
# Generated by Django 4.1.7 on 2023-03-06 10:47
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')], max_length=10)),
('venue', models.CharField(max_length=1000)),
],
),
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.TextField(max_length=100)),
('estimated_hours', models.FloatField()),
('course', models.CharField(max_length=1000)),
('location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='widget_calendar.location')),
],
),
]
from django.db import models from django.db import models
from django.utils import timezone
# Create your models here.
class Location(models.Model):
ONSITE = 'onsite'
ONLINE = 'online'
HYBRID = 'hybrid'
MODE_CHOICES = [
(ONSITE, 'Onsite'),
(ONLINE, 'Online'),
(HYBRID, 'Hybrid'),
]
mode = models.CharField(max_length=10, choices=MODE_CHOICES)
venue = models.CharField(max_length=1000)
class Event(models.Model):
target_datetime = models.DateTimeField()
activity = models.TextField(max_length=100)
estimated_hours = models.FloatField()
location = models.ForeignKey(Location, on_delete=models.CASCADE)
course = models.CharField(max_length=1000)
def __str__(self):
return '{}, {}'.format(self.target_datetime, self.activity)
\ No newline at end of file
from django.test import TestCase from django.test import TestCase
# Create your tests here.
from django.contrib import admin
from django.urls import path from django.urls import path
from .views import index from.views import index
urlpatterns = [ urlpatterns = [
path('', index, name="index"), path('', index, name='index'),
] ]
app_name = "widget_calendar"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from.models import Event, Location
def index(request): def index(request):
return HttpResponse('') page_content="""<H1>Widget’s Calendar of Activities</H1>"""
\ No newline at end of file for event in Event.objects.all():
newEventDateTime = event.target_datetime.strftime("%m-%d-%Y %I:%M %p")
page_content += """<ul>
<li>Date and Time: {}<br>
<li>Activity: {}<br>
<li>Estimated Hours: {}<br>
<li>Course/Section: {}<br>
<li>Mode: {}<br>
<li>Venue: {}<br>
</ul>""".format(event.target_datetime, event.activity,
event.estimated_hours, event.course,
event.location.mode, event.location.venue)
return HttpResponse(page_content)
\ No newline at end of file
...@@ -45,6 +45,7 @@ INSTALLED_APPS = [ ...@@ -45,6 +45,7 @@ INSTALLED_APPS = [
'assignments', 'assignments',
'dashboard', 'dashboard',
'forum', 'forum',
'widget_calendar',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
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