1234567891011121314151617181920212223242526 |
- from django.http import HttpResponseRedirect
- from django.shortcuts import render
- from .forms import CreateEventForm
- from .models import Event
- def index(request):
- return render(request, 'zitap/index.html')
- def about(request):
- return render(request, 'zitap/about.html')
- def create_event(request):
- if request.method == 'POST':
- form = CreateEventForm(request.POST)
- if form.is_valid():
- data = form.cleaned_data
- print(data)
- event = Event.objects.create(name=data['event_name'])
- for date in data['event_date']:
- event.date_set.create(date=date)
- event.save()
- return HttpResponseRedirect(f'/{event.url}')
- else:
- form = CreateEventForm()
- return render(request, 'zitap/create-event.html', {'form': form})
|