Commit b12b5ef9 authored by Angelo Alvarez's avatar Angelo Alvarez

Added views and urls of Calendar app

parent e372e982
...@@ -16,7 +16,7 @@ class Location(models.Model): ...@@ -16,7 +16,7 @@ class Location(models.Model):
return self.venue return self.venue
class Event(models.Model): class Event(models.Model):
target_datetime = models.DateTimeField() target_datetime = models.DateTimeField("Target Date and Time",)
activity = models.CharField(max_length=50) activity = models.CharField(max_length=50)
estimated_hours = models.FloatField() estimated_hours = models.FloatField()
location = models.ForeignKey(Location, on_delete=models.CASCADE) location = models.ForeignKey(Location, on_delete=models.CASCADE)
......
# <appname>/urls.py
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name='index'),
]
app_name = "calendar_app"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse
from .models import Event
# Create your views here. # Create your views here.
def index(request):
eventInfo = ""
events = Event.objects.all()
for event in events:
eventInfo += '''
Date and Time: {} <br>
Activity: {} <br>
Estimated Hours: {} <br>
Course/Section: {} {}-{} <br>
Mode: {} <br>
Venue: {} <br>
<br>
'''.format(
event.target_datetime.strftime("%m/%d/%Y, %I:%M %p"),
event.activity(),
event.estimated_hours(),
event.course.code(), event.course.title(), event.course.section(),
event.location.mode(),
event.location.venue()
)
return HttpResponse('''
Widget's Calendar of Activities <br>
<br>
{}
'''.format(eventInfo))
\ No newline at end of file
...@@ -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