Commit 9c950c55 authored by Ysabella Panghulan's avatar Ysabella Panghulan

created EventCreateView in views.py

parent e340d57b
...@@ -2,6 +2,7 @@ from django.shortcuts import render, redirect ...@@ -2,6 +2,7 @@ from django.shortcuts import render, redirect
from django.http import HttpResponse from django.http import HttpResponse
from .models import Location, Event from .models import Location, Event
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
# Create your views here. # Create your views here.
def Calendar(request): def Calendar(request):
...@@ -15,4 +16,21 @@ def Calendar(request): ...@@ -15,4 +16,21 @@ def Calendar(request):
class EventDetailView(DetailView): class EventDetailView(DetailView):
model = Event model = Event
template_name = 'widget_calendar/event-details.html' template_name = 'widget_calendar/event-details.html'
\ No newline at end of file
class EventCreateView(CreateView):
model = Event
template_name = 'widget_calendar/event-add.html'
fields = '__all__'
def post(self, request, *args, **kwargs):
form = EventForm(request.POST)
if form.is_valid():
event = form.save()
return redirect('event-details', pk=event.pk)
else:
form = EventForm()
context = {
'form': form
}
return render(request, 'widget_calendar/event-add.html', context)
\ 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