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.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView from django.views.generic.edit import CreateView, UpdateView
from .models import Event from .forms import EventForm
from .models import Event
def event_view(request):
events = Event.objects.all()
context = {'events' : events}
return render(request, 'event_management/events.html', context)
class EventDetailView(DetailView): class EventDetailView(DetailView):
model = Event model = Event
...@@ -16,14 +14,29 @@ class EventDetailView(DetailView): ...@@ -16,14 +14,29 @@ class EventDetailView(DetailView):
class EventListView(ListView): class EventListView(ListView):
model = Event model = Event
fields = '__all__'
template_name = 'event_management/event-list.html' template_name = 'event_management/event-list.html'
class EventCreateView(CreateView): class EventCreateView(CreateView):
model = Event model = Event
fields = '__all__' 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): class EventUpdateView(UpdateView):
model = Event model = Event
fields = '__all__' fields = '__all__'
template_name = 'event/event-update.html' template_name = 'event_management/event-form.html'
\ No newline at end of file \ 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