Commit c9687cbf authored by Rau Layug's avatar Rau Layug

Updated calendarapp views for Location model

parent 975880ff
...@@ -8,9 +8,12 @@ class Location(models.Model): ...@@ -8,9 +8,12 @@ class Location(models.Model):
("ONL", "Online"), ("ONL", "Online"),
("OAO", "Onsite and Online") ("OAO", "Onsite and Online")
] ]
mode = models.CharField(max_length=3, choices=MODE_CHOICES) mode = models.CharField(max_length=18, choices=MODE_CHOICES)
venue = models.CharField(max_length=150) venue = models.CharField(max_length=150)
def __str__(self):
return self.venue
class Event(models.Model): class Event(models.Model):
target_date = models.DateField() target_date = models.DateField()
...@@ -21,15 +24,4 @@ class Event(models.Model): ...@@ -21,15 +24,4 @@ class Event(models.Model):
location = models.ForeignKey(Location, on_delete=models.CASCADE) location = models.ForeignKey(Location, on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return '{} with {} hours duration on {} '.format(self.activity, self.estimated_hours, self.target_date) return self.activity
def get_display(self):
display = (
"Target Date: " + str(self.target_date) + "<br>" +
"Activity: " + str(self.activity) + "<br>" +
"Estimated Hours: " + str(self.estimated_hours) + "<br>" +
"Course/Section: " + '" ".join(str(self.course.course_code),str(self.course.course_title),str(self.course.section))' + "<br>" +
"Mode: " + str(self.location) + "<br>" +
"Venue: " + str(self.location) + "<br>"
)
return display
...@@ -7,10 +7,18 @@ from .models import Event, Location ...@@ -7,10 +7,18 @@ from .models import Event, Location
# Create your views here. # Create your views here.
def index(request): def index(request):
response = "This is the Calendar page!<br><br>" response = "This is the Calendar page!<br><br>"
events = Event.objects.all() events = Event.objects.all()
for event in events: for event in events:
response += event.get_display() + "<br>" location = event.location
target_date = event.target_date
activity = event.activity
estimated_hours = event.estimated_hours
course_section = "foo"
mode = location.get_mode_display()
venue = location.venue
response += "Target Date: {}<br>Activity: {}<br>Estimated Hours: {}<br>Course/Section: {}<br>Mode: {}<br>Venue: {}<br><br>".format(target_date, activity, estimated_hours, course_section, mode,
venue)
return HttpResponse(response) return HttpResponse(response)
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