views.py 827 B

1234567891011121314151617181920212223242526
  1. from django.http import HttpResponseRedirect
  2. from django.shortcuts import render
  3. from .forms import CreateEventForm
  4. from .models import Event
  5. def index(request):
  6. return render(request, 'zitap/index.html')
  7. def about(request):
  8. return render(request, 'zitap/about.html')
  9. def create_event(request):
  10. if request.method == 'POST':
  11. form = CreateEventForm(request.POST)
  12. if form.is_valid():
  13. data = form.cleaned_data
  14. print(data)
  15. event = Event.objects.create(name=data['event_name'])
  16. for date in data['event_date']:
  17. event.date_set.create(date=date)
  18. event.save()
  19. return HttpResponseRedirect(f'/{event.url}')
  20. else:
  21. form = CreateEventForm()
  22. return render(request, 'zitap/create-event.html', {'form': form})