Skip to content

Commit

Permalink
changes to the ExchangeCreateView
Browse files Browse the repository at this point in the history
  • Loading branch information
rladdusaw committed Jul 26, 2016
1 parent 0d10add commit 77a3151
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
18 changes: 16 additions & 2 deletions exchange/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,29 @@ def get(self, request):
user = User.objects.get(id=request.user.id)
exchange_list = Exchange.objects.filter(owner=user)
form = self.form_class
return render(request, 'create_exchange.html', {'form': form, 'exchange_list': exchange_list})
return render(
request,
'create_exchange.html',
{'form': form, 'exchange_list': exchange_list}
)

def post(self, request, *args, **kwargs):
user = User.objects.get(id=request.user.id)
exchange_list = Exchange.objects.filter(owner=user)
form = self.get_form()
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(form)

def form_valid(self, form):
exchange = form.save(commit=False)
exchange.owner = self.request.user
exchange.save()
return HttpResponseRedirect(self.get_success_url())




class ExchangeDetailView(LoginRequiredMixin, CreateView, SingleObjectMixin):
template_name = 'exchange_detail.html'
model = Exchange
Expand Down
1 change: 0 additions & 1 deletion wishlist/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ def form_valid(self, form):
return HttpResponseRedirect(
'/wishlist/detail/%s/' % (self.kwargs['current_list'],)
)


0 comments on commit 77a3151

Please sign in to comment.