Commit e584e153 authored by Jose Gabriel L. Salas's avatar Jose Gabriel L. Salas

updated views to display all events'/activities' details

parent 277d640f
......@@ -5,29 +5,33 @@ from .models import Event, Location
class EventAdmin(admin.ModelAdmin):
model = Event
search_fields = ('activity','target_datetime','course', )
list_display = ('activity','target_datetime', )
list_filter = ('target_datetime','course', )
search_fields = ('activity', 'target_datetime', 'course', )
list_display = ('activity', 'target_datetime', )
list_filter = ('target_datetime', 'course', )
fieldsets = [
('Activity', {
'fields':[('activity','course' ),
'target_datetime','location','estimated_hours']
'fields': [
('activity', 'course', ),
'target_datetime', 'location', 'estimated_hours'
]
}),
]
class LocationAdmin(admin.ModelAdmin):
model = Location
search_fields = ('venue','mode', )
list_display = ('venue','mode', )
search_fields = ('venue', 'mode', )
list_display = ('venue', 'mode', )
list_filter = ('mode', )
class EventInline(admin.TabularInline):
model = Event
class LocationInline(admin.TabularInline):
model = Location
admin.site.register(Event, EventAdmin)
admin.site.register(Location, LocationAdmin)
# Generated by Django 4.1.7 on 2023-03-04 15:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('widget_calendar', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='location',
name='mode',
field=models.CharField(choices=[('Onsite', 'Onsite'), ('Online', 'Online'), ('Hybrid', 'Hybrid')], default='Onsite', max_length=6),
),
]
# Generated by Django 4.1.7 on 2023-03-04 16:31
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('widget_calendar', '0002_alter_location_mode'),
]
operations = [
migrations.AlterField(
model_name='event',
name='location',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='event', to='widget_calendar.location'),
),
]
......@@ -2,20 +2,23 @@ from django.db import models
class Location(models.Model):
onsite = 'OS'
online = 'OL'
hybrid = 'HB'
onsite = 'Onsite'
online = 'Online'
hybrid = 'Hybrid'
mode_choices = [
(onsite, 'Onsite'),
(online, 'Online'),
(hybrid, 'Hybrid'),
]
mode = models.CharField(max_length=2, choices=mode_choices, default=onsite, )
mode = models.CharField(
max_length=6, choices=mode_choices, default=onsite,
)
venue = models.CharField(max_length=100)
def __str__(self):
return '{}, {}'.format(self.mode, self.venue)
class Event(models.Model):
target_datetime = models.DateTimeField()
activity = models.CharField(max_length=255)
......
from django.http import HttpResponse
from .models import Event, Location
def index(request):
return HttpResponse('display calendar page')
\ No newline at end of file
return_string = "<p>Widget's Calendar of Activities</p> <ul style='list-style: none; padding: 0; margin: 0;'> "
for events in Event.objects.all():
round_hours = ("{:0.0f}".format(events.estimated_hours))
return_string += '<li>Date and Time: {}<br>'.format(
events.target_datetime.strftime('%m/%d/%Y, %H:%M %p')
)
return_string += 'Activity: {}<br>'.format(events.activity)
return_string += 'Estimated Hours: {}<br>'.format(round_hours)
return_string += 'Course/Section: {}<br>'.format(events.course)
return_string += 'Mode: {}<br>'.format(events.location.mode)
return_string += 'Venue: {}<br>'.format(events.location.venue)
return_string += '<br>'
return_string += '</ul>'
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
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