Commit 4cd49e56 authored by Gabriel Geraldo's avatar Gabriel Geraldo

implemented add activity function

parent 8dac69ae
from django import forms
from .models import Event
class EventCreateForm(forms.ModelForm):
class Meta:
model = Event
fields = ['activity', 'target_datetime', 'estimated_hours',
'location', 'course']
widgets = {
'target_datetime': forms.DateTimeInput(attrs={'type': 'datetime-local'})
}
...@@ -20,7 +20,7 @@ class Location(models.Model): ...@@ -20,7 +20,7 @@ class Location(models.Model):
venue = models.CharField(max_length=255) venue = models.CharField(max_length=255)
def __str__(self): def __str__(self):
return '{} ({})'.format( return '{} - {}'.format(
self.venue, self.venue,
self.mode self.mode
) )
...@@ -38,7 +38,11 @@ class Event(models.Model): ...@@ -38,7 +38,11 @@ class Event(models.Model):
self.activity, self.activity,
self.course self.course
) )
def get_absolute_url(self): def get_absolute_url(self):
return reverse("widget_calendar:event_details", kwargs={"pk": self.pk}) return reverse("widget_calendar:event_details", kwargs={"pk": self.pk})
def get_date(self):
return self.target_datetime.strftime("%m/%d/%Y")
def get_time(self):
return self.target_datetime.strftime("%I:%M %p")
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add Activity{% endblock %}
{% block content %}
<h1>Add a new activity:</h1>
<div class="new_user">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save New Activity</button>
</form>
</div>
{% endblock %}
from django.urls import path from django.urls import path
from .views import index, EventDetailView from .views import index, EventDetailView, EventCreateFormView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('events/<int:pk>/details', EventDetailView.as_view(), name='event_details'), path('events/<int:pk>/details', EventDetailView.as_view(), name='event_details'),
path('events/add', EventCreateFormView.as_view(), name='event_add'),
] ]
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.http import HttpResponse from django.http import HttpResponse
from .models import Event, Location from .models import Event, Location
from .forms import EventCreateForm
from django.views.generic.edit import CreateView, FormView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
def index(HttpRequest): def index(HttpRequest):
...@@ -11,3 +13,8 @@ def index(HttpRequest): ...@@ -11,3 +13,8 @@ def index(HttpRequest):
class EventDetailView(DetailView): class EventDetailView(DetailView):
model = Event model = Event
template_name = "widget_calendar/event-details.html" template_name = "widget_calendar/event-details.html"
class EventCreateFormView(CreateView):
form_class = EventCreateForm
# taken from: https://stackoverflow.com/questions/27321692/override-a-django-generic-class-based-view-widget
template_name = "widget_calendar/event-add.html"
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