Modified old widget_calendar code to match specs (i.e. turning course into...

Modified old widget_calendar code to match specs (i.e. turning course into foreignkey, changing html layout)
parent fcf8b771
from django import forms
from .models import Event
class WidgetUserForm(forms.ModelForm):
class Meta:
model = Event
fields = ['activity', 'target_datetime', 'estimated_hours', 'location', 'course',]
\ No newline at end of file
from django.db import models from django.db import models
from django.urls import reverse
class Location(models.Model): class Location(models.Model):
modechoices = [ modechoices = [
...@@ -16,12 +17,19 @@ class Location(models.Model): ...@@ -16,12 +17,19 @@ class Location(models.Model):
def __str__(self): def __str__(self):
return '{}, {}'.format(self.mode, self.venue) return '{}, {}'.format(self.mode, self.venue)
class Course(models.Model):
course_code = models.CharField(max_length=10)
section = models.CharField(max_length=5)
class Event(models.Model): class Event(models.Model):
target_datetime = models.CharField(max_length=50) target_datetime = models.CharField(max_length=50)
activity = models.TextField(max_length=300) activity = models.TextField(max_length=300)
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=150) course = models.ForeignKey(Course, on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return self.activity return self.activity
\ No newline at end of file
def get_absolute_url(self):
return reverse('widget_calendar:event-details', kwargs={"pk": self.pk})
\ No newline at end of file
<p>Widget's Calendar of Activities<br><br></p> {% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Calendar of Activities{% endblock %}
{% block content %}
<h2>Widget's Calendar of Activities</h2>
{% for event in events %} {% for event in events %}
<p> <a href="{{ event.get_absolute_url }}">{{event.activity}}</a><br>
{{ event.target_datetime }}<br>
Activity: {{ event.activity }}<br>
Estimated Hours: {{ event.estimated_hours }}<br>
Course/Section: {{ event.course }}<br>
Mode: {{ event.location.mode }}<br>
Venue: {{ event.location.venue }}
</p>
{% endfor %} {% endfor %}
<br>
<a href="{% url 'widget_calendar:event-add' %}" class="button"> New Activity </a><br>
<a href="{% url 'dashboard:pageview' %}">Dashboard</a><br>
<a href="{% url 'announcements:pageview' %}">Announcements</a><br>
<a href="{% url 'forum:pageview' %}">Forum</a><br>
<a href="{% url 'assignments:pageview' %}">Assignments</a><br>
{% endblock %}
\ No newline at end of file
...@@ -3,7 +3,10 @@ from django.urls import path ...@@ -3,7 +3,10 @@ from django.urls import path
from .views import pageview from .views import pageview
urlpatterns = [ urlpatterns = [
path('', pageview, name='pageview') path('', pageview, name='pageview'),
path('widget_calender/events/<int:pk>/details', Widget_CalenderDetailView.as_view(), name='event-details'),
path('widget_calender/add', Widget_CalendarCreateView.as_view(), name='event-add'),
path('widget_calender/events/<int:pk>/edit', Widget_CalendarEventUpdateView.as_view(), name='event-edit'),
] ]
app_name = "widget_calendar" app_name = "widget_calendar"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Event, Location from .models import Event, Location
def pageview(request): def pageview(request):
...@@ -6,3 +8,10 @@ def pageview(request): ...@@ -6,3 +8,10 @@ def pageview(request):
locations = Location.objects.all() locations = Location.objects.all()
return render(request, 'widget_calendar/widget_calendar.html', {'events': events, 'locations': locations}) return render(request, 'widget_calendar/widget_calendar.html', {'events': events, 'locations': locations})
class Widget_CalendarDetailView(DetailView):
def get(self, request, pk):
event = Event.objects.get(pk=pk)
course = event.course
venue = event.location
return render(request, 'dashboard/widgetuser-details.html', {'department': department, 'user': user})
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