def create(request): if request.method == 'POST': form = ExchangeForm(request.POST) if form.is_valid(): exchange = form.save(user=request.user) return redirect('exchange-list') else : form = ExchangeForm() return {'form': form}
def edit(request, exchange_id): exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == 'POST': form = ExchangeForm(request.POST, instance=exchange) if form.is_valid(): exchange = form.save(user=request.user) return redirect('exchange-list') else : form = ExchangeForm(instance=exchange) user_exchanges = exchange.userexchange_set.all() user_exchange_exclusions = UserExchangeExclusion.objects.filter(exchange=exchange) return { 'form': form, 'exchange': exchange, 'user_exchanges': user_exchanges, 'user_exchange_exclusions': user_exchange_exclusions }
def create(request): if request.method == 'POST': form = ExchangeForm(request.POST) if form.is_valid(): exchange = form.save(user=request.user) return redirect('exchange-list') else: form = ExchangeForm() return {'form': form}
def edit(request, exchange_id): exchange = get_object_or_404(Exchange, pk=exchange_id) if request.method == 'POST': form = ExchangeForm(request.POST, instance=exchange) if form.is_valid(): exchange = form.save(user=request.user) return redirect('exchange-list') else: form = ExchangeForm(instance=exchange) user_exchanges = exchange.userexchange_set.all() user_exchange_exclusions = UserExchangeExclusion.objects.filter( exchange=exchange) return { 'form': form, 'exchange': exchange, 'user_exchanges': user_exchanges, 'user_exchange_exclusions': user_exchange_exclusions }