Exemple #1
0
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}
Exemple #2
0
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
    }