Commit b476f48b authored by Ciella Francisco's avatar Ciella Francisco 😵

Edited views.py to enable creation of events via forms under the EventCreateView class

parent 02f05d88
from django.shortcuts import render
from typing import Any
from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView
from .models import Event
def event_view(request):
events = Event.objects.all()
context = {'events' : events}
return render(request, 'event_management/events.html', context)
from .forms import EventForm
from .models import Event
class EventDetailView(DetailView):
model = Event
......@@ -16,14 +14,29 @@ class EventDetailView(DetailView):
class EventListView(ListView):
model = Event
fields = '__all__'
template_name = 'event_management/event-list.html'
class EventCreateView(CreateView):
model = Event
fields = '__all__'
template_name = 'event_management/event-create.html'
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
context['form'] = EventForm()
return context
def post(self, request, *args, **kwargs):
form = EventForm(request.POST)
if form.is_valid():
return self.get(request, *args, **kwargs)
else:
return render(request, self.template_name, {'form': form})
template_name = 'event_management/event-form.html'
class EventUpdateView(UpdateView):
model = Event
fields = '__all__'
template_name = 'event/event-update.html'
\ No newline at end of file
template_name = 'event_management/event-form.html'
\ 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