Added calendar app

parent de9e295a
from django.contrib import admin from django.contrib import admin
from .models import Event, Location
# Register your models here. # Register your models here.
class EventAdmin(admin.ModelAdmin):
model = Event
list_display = ("target_datetime", "activity", "estimated_hours", "locations", "course",)
search_field = ("target_datetime", "activity", "estimated_hours", "locations", "course",)
list_filter = ("target_datetime", "activity", "estimated_hours", "locations", "course",)
class LocationAdmin(admin.ModelAdmin):
model = Location
list_display = ("modes", "venue",)
search_field = ("modes", "venue",)
list_filter = ("venue",)
admin.site.register(Event, EventAdmin)
admin.site.register(Location, LocationAdmin)
# Generated by Django 3.2 on 2023-03-02 07:20
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Event',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('target_datetime', models.DateTimeField(verbose_name='Target Date & Time')),
('activity', models.CharField(max_length=300)),
('estimated_hours', models.FloatField(default=0)),
('locations', models.CharField(max_length=300)),
('course', models.CharField(max_length=300)),
],
),
migrations.CreateModel(
name='Location',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('venue', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='calendars.event')),
],
),
]
# Generated by Django 3.2 on 2023-03-02 07:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('calendars', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='location',
name='modes',
field=models.CharField(choices=[('onsite', 'onsite'), ('online', 'online')], default='onsite', max_length=150),
),
]
# Generated by Django 3.2 on 2023-03-02 08:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('calendars', '0002_location_modes'),
]
operations = [
migrations.AlterField(
model_name='location',
name='venue',
field=models.CharField(max_length=200),
),
]
# Generated by Django 3.2 on 2023-03-02 08:03
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('calendars', '0003_alter_location_venue'),
]
operations = [
migrations.AlterField(
model_name='location',
name='venue',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='calendars.event'),
),
]
# Generated by Django 3.2 on 2023-03-02 08:11
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('calendars', '0004_alter_location_venue'),
]
operations = [
migrations.AlterField(
model_name='event',
name='locations',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='calendars.location'),
),
migrations.AlterField(
model_name='location',
name='venue',
field=models.CharField(max_length=150),
),
]
from django.db import models from django.db import models
# Create your models here. # Create your models here.
class Location(models.Model):
Onsite = 'onsite'
Online = 'online'
mode_options = [
(Onsite, 'onsite'),
(Online, 'online'),
]
modes = models.CharField(max_length=150, choices=mode_options, default=Onsite)
venue = models.CharField(max_length=150)
def __str__(self):
return self.venue
class Event(models.Model):
target_datetime = models.DateTimeField("Target Date & Time")
activity = models.CharField(max_length=300)
estimated_hours = models.FloatField(default=0)
locations = models.ForeignKey(Location, on_delete=models.CASCADE)
course = models.CharField(max_length=300)
def __str__(self):
return self.activity
# models.ForeignKeys('assignments.Course', on_delete=models.CASCADE)
from django.urls import path
from . import views
urlpatterns = [
path('', views.calendarschedule, name = "calendarschedule")
]
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import Event
# Create your views here. # Create your views here.
def calendarschedule(request):
schedule = Event.objects.all()
response ="Widgets's Calendar of Activities<br><br>"
for sched in schedule:
datetime = sched.target_datetime.strftime("%m/%d/%Y, %H:%M %p")
activities = sched.activity
estimatedhrs = str(sched.estimated_hours)
courses = sched.course
mode = sched.locations.modes
ven = sched.locations.venue
response += "Date and Time: "+ datetime + "<br>Activity: " + activities + "<br>Estimated Hours: " + estimatedhrs +"<br>Course/Section: " + courses + "<br>Mode: " + mode + "<br>Venue: " + ven + "<br>"
return HttpResponse(response)
\ No newline at end of file
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