Implemented Edit and Add pages by using forms and templates

parent 5ef953fd
# Generated by Django 4.1.6 on 2023-05-15 14:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('widget_calendar', '0003_course_alter_event_course'),
]
operations = [
migrations.AddField(
model_name='course',
name='course_title',
field=models.CharField(default='a', max_length=50),
preserve_default=False,
),
]
...@@ -19,6 +19,7 @@ class Location(models.Model): ...@@ -19,6 +19,7 @@ class Location(models.Model):
class Course(models.Model): class Course(models.Model):
course_code = models.CharField(max_length=10) course_code = models.CharField(max_length=10)
course_title = models.CharField(max_length=50)
section = models.CharField(max_length=5) section = models.CharField(max_length=5)
class Event(models.Model): class Event(models.Model):
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Activity{% endblock %}
{% block content %}
<h2>Add a new activity:</h2>
<p>
<form action='' method="POST">
{% csrf_token %}
Activity: {{ form.activity }}<br><br>
Target Date/Time: {{ form.target_datetime }}
Estimated Hours: {{ form.estimated_hours }}
Location: {{ form.location }}
Course: {{ form.course }}
<input type="submit" value="Save New Activity">
</form>
</p>
{% endblock %}
\ No newline at end of file
...@@ -4,10 +4,13 @@ ...@@ -4,10 +4,13 @@
{% block content %} {% block content %}
<h2>{{ event.activity }}</h2> <h2>{{ event.activity }}</h2>
<h3>Date and Time: {{ event.target_datetime }}</h3> <h3>Date and Time: {{ event.target_datetime }}</h3>
<h3>{{ department.home_unit }}</h3> <h3>Estimated Hours: {{ event.estimated_hours }}</h3>
<h3>{{ course.course_code }} {{ course.course_title }} - {{ course.section }}</h3>
<h3>Mode: {{ location.mode }}</h3>
<h3>Venue: {{ location.venue }}</h3>
<br> <br>
<form action='edit'> <form action='edit'>
<input type="submit" value="Edit Widget User"/> <input type="submit" value="Edit Activity"/>
</form> </form>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Activity{% endblock %}
{% block content %}
<h2>Edit Activity</h2>
<p>
<form action='' method="POST">
{% csrf_token %}
Activity: {{ form.activity }}<br><br>
Target Date/Time: {{ form.target_datetime }}
Estimated Hours: {{ form.estimated_hours }}
Location: {{ form.location }}
Course: {{ form.course }}
<input type="submit" value="Save New Activity">
</form>
</p>
{% endblock %}
\ No newline at end of file
...@@ -13,22 +13,16 @@ class Widget_CalendarDetailView(DetailView): ...@@ -13,22 +13,16 @@ class Widget_CalendarDetailView(DetailView):
def get(self, request, pk): def get(self, request, pk):
event = Event.objects.get(pk=pk) event = Event.objects.get(pk=pk)
course = event.course course = event.course
venue = event.location location = event.location
return render(request, 'widget_calendar/event-details.html', {'event': event, 'course': course, 'venue': venue}) return render(request, 'widget_calendar/event-details.html', {'event': event, 'course': course, 'location': location})
class Widget_CalendarCreateView(CreateView): class Widget_CalendarCreateView(CreateView):
def get(self, request, pk): model = Event
event = Event.objects.get(pk=pk) fields = '__all__'
course = event.course template_name = 'widget_calendar/event-add.html'
venue = event.location
return render(request, 'widget_calendar/event-details.html', {'event': event, 'course': course, 'venue': venue})
class Widget_CalendarEventUpdateView(UpdateView): class Widget_CalendarEventUpdateView(UpdateView):
def get(self, request, pk): model = Event
event = Event.objects.get(pk=pk) fields = '__all__'
course = event.course template_name = 'widget_calendar/event-edit.html'
venue = event.location \ No newline at end of file
return render(request, 'widget_calendar/event-details.html', {'event': event, 'course': course, 'venue': venue})
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