Commit 975880ff authored by Rau Layug's avatar Rau Layug

Added Location model in calendarapp & updated calendarapp views

parent 50919849
from django.contrib import admin from django.contrib import admin
from .models import Event from .models import Event, Location
# Register your models here. # Register your models here.
class LocationAdmin(admin.ModelAdmin):
model = Location
list_display = ('mode', 'venue')
class EventAdmin(admin.ModelAdmin): class EventAdmin(admin.ModelAdmin):
model = Event model = Event
list_display = ('target_date', 'activity', 'estimated_hours') list_display = ('target_date', 'activity', 'estimated_hours', 'location')
admin.site.register(Location, LocationAdmin)
admin.site.register(Event, EventAdmin) admin.site.register(Event, EventAdmin)
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-03-30 15:41
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('calendarapp', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Location',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('mode', models.CharField(choices=[('ONS', 'Onsite'), ('ONL', 'Online'), ('OAO', 'Onsite and Online')], max_length=3)),
('venue', models.CharField(max_length=150)),
],
),
migrations.AddField(
model_name='event',
name='location',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='calendarapp.location'),
preserve_default=False,
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class Location(models.Model):
MODE_CHOICES = [
("ONS", "Onsite"),
("ONL", "Online"),
("OAO", "Onsite and Online")
]
mode = models.CharField(max_length=3, choices=MODE_CHOICES)
venue = models.CharField(max_length=150)
class Event(models.Model): class Event(models.Model):
target_date = models.DateField() target_date = models.DateField()
activity = models.CharField(max_length=150) activity = models.CharField(max_length=150)
estimated_hours = models.FloatField() estimated_hours = models.FloatField()
# to add when Course model is added in Assignments
# course =
location = models.ForeignKey(Location, on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return '{} with {} hours duration on {} '.format(self.activity, self.estimated_hours, self.target_date) return '{} with {} hours duration on {} '.format(self.activity, self.estimated_hours, self.target_date)
\ No newline at end of file
def get_display(self):
display = (
"Target Date: " + str(self.target_date) + "<br>" +
"Activity: " + str(self.activity) + "<br>" +
"Estimated Hours: " + str(self.estimated_hours) + "<br>" +
"Course/Section: " + '" ".join(str(self.course.course_code),str(self.course.course_title),str(self.course.section))' + "<br>" +
"Mode: " + str(self.location) + "<br>" +
"Venue: " + str(self.location) + "<br>"
)
return display
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
def index(request): from .models import Event, Location
return HttpResponse('This is the Calendar page!')
# Create your views here. # Create your views here.
def index(request):
response = "This is the Calendar page!<br><br>"
events = Event.objects.all()
for event in events:
response += event.get_display() + "<br>"
return HttpResponse(response)
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