예제 #1
0
def create_event(request):
    if request.method == "POST":
        form = EventForm(request.POST)
        if form.is_valid():
            new_event = form.save()
            attendee = Attendee(user=request.user, event=new_event, is_managing=True)
            attendee.save()
            return redirect("detail", event_id=new_event.pk)
    else:
        form = EventForm()

    context = {"form": form, "button_label": "Create Event"}
    return render(request, "events/create.html", context)
예제 #2
0
def edit(request, event_id):
    event = get_object_or_404(Events, pk=event_id)

    if request.method == "POST":
        form = EventForm(request.POST, instance=event)
        if form.is_valid():
            form.save()
            return redirect("detail", event_id=event.pk)
    else:
        form = EventForm(instance=event)

    context = {"form": form, "button_label": "Save Event"}

    return render(request, "events/create.html", context)