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 ...@@ -5,29 +5,33 @@ from .models import Event, Location
class EventAdmin(admin.ModelAdmin): class EventAdmin(admin.ModelAdmin):
model = Event model = Event
search_fields = ('activity','target_datetime','course', ) search_fields = ('activity', 'target_datetime', 'course', )
list_display = ('activity','target_datetime', ) list_display = ('activity', 'target_datetime', )
list_filter = ('target_datetime','course', ) list_filter = ('target_datetime', 'course', )
fieldsets = [ fieldsets = [
('Activity', { ('Activity', {
'fields':[('activity','course' ), 'fields': [
'target_datetime','location','estimated_hours'] ('activity', 'course', ),
}), 'target_datetime', 'location', 'estimated_hours'
] ]
}),
]
class LocationAdmin(admin.ModelAdmin): class LocationAdmin(admin.ModelAdmin):
model = Location model = Location
search_fields = ('venue','mode', ) search_fields = ('venue', 'mode', )
list_display = ('venue','mode', ) list_display = ('venue', 'mode', )
list_filter = ('mode', ) list_filter = ('mode', )
class EventInline(admin.TabularInline): class EventInline(admin.TabularInline):
model = Event model = Event
class LocationInline(admin.TabularInline): class LocationInline(admin.TabularInline):
model = Location model = Location
admin.site.register(Event, EventAdmin) admin.site.register(Event, EventAdmin)
admin.site.register(Location, LocationAdmin) admin.site.register(Location, LocationAdmin)
\ No newline at end of file
# 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,26 +2,29 @@ from django.db import models ...@@ -2,26 +2,29 @@ from django.db import models
class Location(models.Model): class Location(models.Model):
onsite = 'OS' onsite = 'Onsite'
online = 'OL' online = 'Online'
hybrid = 'HB' hybrid = 'Hybrid'
mode_choices = [ mode_choices = [
(onsite, 'Onsite'), (onsite, 'Onsite'),
(online, 'Online'), (online, 'Online'),
(hybrid, 'Hybrid'), (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) venue = models.CharField(max_length=100)
def __str__(self): def __str__(self):
return '{}, {}'.format(self.mode, self.venue) return '{}, {}'.format(self.mode, self.venue)
class Event(models.Model): class Event(models.Model):
target_datetime = models.DateTimeField() target_datetime = models.DateTimeField()
activity = models.CharField(max_length=255) activity = models.CharField(max_length=255)
estimated_hours = models.FloatField() estimated_hours = models.FloatField()
location = models.ForeignKey(Location, on_delete=models.CASCADE) location = models.ForeignKey(Location, on_delete=models.CASCADE)
course = models.CharField(max_length=100) course = models.CharField(max_length=100)
def __str__(self): def __str__(self):
return '{}, {}'.format(self.activity, self.target_datetime) return '{}, {}'.format(self.activity, self.target_datetime)
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Event, Location
def index(request): 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