Commit e54ae1ff authored by Rau Layug's avatar Rau Layug

Merge branch 'layug/calendar' into 'master'

Merge layug/calendar into master

See merge request !7
parents cab13277 f4f5b0c5
from django.contrib import admin
from .models import Event
from .models import Event, Location
# Register your models here.
class LocationAdmin(admin.ModelAdmin):
model = Location
list_display = ('mode', 'venue')
class EventAdmin(admin.ModelAdmin):
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)
\ 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
# Create your models here.
class Location(models.Model):
MODE_CHOICES = [
("ONS", "Onsite"),
("ONL", "Online"),
("OAO", "Onsite and Online")
]
mode = models.CharField(max_length=18, choices=MODE_CHOICES)
venue = models.CharField(max_length=150)
def __str__(self):
return self.venue
class Event(models.Model):
target_date = models.DateField()
activity = models.CharField(max_length=150)
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):
return '{} with {} hours duration on {} '.format(self.activity, self.estimated_hours, self.target_date)
\ No newline at end of file
return self.activity
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse('This is the Calendar page!')
from .models import Event, Location
# Create your views here.
def index(request):
response = "This is the Calendar page!<br><br>"
events = Event.objects.all()
for event in events:
location = event.location
target_date = event.target_date
activity = event.activity
estimated_hours = event.estimated_hours
course_section = "foo"
mode = location.get_mode_display()
venue = location.venue
response += "Target Date: {}<br>Activity: {}<br>Estimated Hours: {}<br>Course/Section: {}<br>Mode: {}<br>Venue: {}<br><br>".format(target_date, activity, estimated_hours, course_section, mode,
venue)
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