def edit_activity(request, activ_id): user = request.user trip_id = 0 if request.method == "POST": activity_form = ActivityForm(request.POST) if activity_form.is_valid(): activity = get_object_or_404(Activity, id=activ_id) activity.activ_name = activity_form.cleaned_data['activ_name'] activity.activ_location = activity_form.cleaned_data['activ_location'] activity.activ_description = activity_form.cleaned_data['activ_description'] activity.expenses = activity_form.cleaned_data['activ_expense'] activity.start_date = activity_form.cleaned_data['activ_start_date'] activity.end_date = activity_form.cleaned_data['activ_end_date'] activity.save() trip_id = activity.trip.id return HttpResponseRedirect(reverse('dashboard', kwargs={"trip_id": trip_id}))
def add_activity(request): user = request.user if request.method == "POST": activity_form = ActivityForm(request.POST) if activity_form.is_valid(): activity = Activity() activity.trip = Trip.objects.get(pk=request.POST.get('trip_activ_id')) activity.activ_name = activity_form.cleaned_data['activ_name'] activity.activ_location = activity_form.cleaned_data['activ_location'] activity.activ_description = activity_form.cleaned_data['activ_description'] activity.expenses = activity_form.cleaned_data['activ_expense'] activity.start_date = activity_form.cleaned_data['activ_start_date'] activity.end_date = activity_form.cleaned_data['activ_end_date'] activity.save() trip_id = request.POST.get('trip_activ_id') return HttpResponseRedirect(reverse('dashboard', kwargs={"trip_id": trip_id}))