def search_edit(request, pk): social_search = get_object_or_404(SocialSearch, user=request.user, pk=pk) if request.method == 'POST': form = SocialSearchForm(request.POST, instance=social_search) if form.is_valid(): form.save() messages.success(request, u'Busca atualizada com sucesso.') return redirect('dashboard_search_list') else: form = SocialSearchForm(instance=social_search) return render(request, 'dashboard/search_edit.html', {'form': form})
def search_new(request): if request.method == 'POST': form = SocialSearchForm(request.POST) if form.is_valid(): social_search = form.save(commit=False) social_search.user = request.user social_search.save() messages.success(request, u'Busca adicionada com sucesso.') return redirect('dashboard_search_list') else: form = SocialSearchForm() return render(request, 'dashboard/search_new.html', {'form': form})