def update(request, player_rut): data = {} player = Player.objects.get(rut=player_rut) if request.method == "GET": data['form'] = PlayerForm(instance=player) else: data['form'] = PlayerForm(request.POST, request.FILES, instance=player) p = data['form'] if p.is_valid(): p.save() return redirect("player_list2") template_name = 'player/agregar.html' return render(request, template_name, data)
def add(request): data = {} if request.method == "POST": data['form'] = PlayerForm(request.POST, request.FILES) if data['form'].is_valid(): data['form'].save() return redirect('player_list') else: data['form'] = PlayerForm() template_name = 'player/agregar.html' return render(request, template_name, data)
def player_add(request): data = {} if request.method == "POST": data['form'] = PlayerForm(request.POST, request.FILES) if data['form'].is_valid(): # aca el formulario valido data['form'].save() return redirect('player_list') else: data['form'] = PlayerForm() data["titulo"] = "Agregar" template_name = 'player/add_player.html' return render(request, template_name, data)
def TemplateAgregar(request): template = 'agregar.html' data = {} if request.method == "POST": data['form'] = PlayerForm(request.POST, request.FILES) if data['form'].is_valid(): # aca el formulario valido data['form'].save() return redirect('player_list') else: data['form'] = PlayerForm() template_name = 'agregar.html' return render(request, template_name, data)
def player_edit(request,pk): data = {} player = Player.objects.get(pk=int(pk)) if request.method == "POST": data['form'] = PlayerForm(request.POST, request.FILES, instance=player) if data['form'].is_valid(): # aca el formulario valido data['form'].save() return redirect('player_list') else: print("Este es el Player ", player) data['form'] = PlayerForm(instance=player) data["titulo"] = "Editar" template_name = 'player/add_player.html' return render(request, template_name, data)
def add_player(request): form = PlayerForm(request.POST or None) context = {'form': form} if request.method == "POST": form = PlayerForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('player_list') else: form = PlayerForm() template_name = 'player/agregar.html' return render(request, template_name, context)
def editar_jugador(request, id_jugador): jugador = Player.objects.get(id=id_jugador) if request.method == 'GET': form = PlayerForm(instance=jugador) else: form = PlayerForm(request.POST, instance=jugador) if form.is_valid(): form.save() return redirect('../listar') return render(request, 'agregar.html', {'form': form})
def editarJugador(request, id_Jugador): template_name = 'player/AgregarPlayer.html' jugador = Player.objects.get(id=id_Jugador) if request.method == 'GET': form = PlayerForm(instance=jugador) else: form = PlayerForm(request.POST, request.FILES, instance=jugador) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('listPlayer')) return render(request, template_name, {'form': form})
def edit(request, player_id): jugador = Player.objects.get(id=player_id) if request.method == 'GET': form = PlayerForm(instance=jugador) else: form = PlayerForm(request.POST, instance=jugador) if form.is_valid(): form.save() return redirect('player_list') template_name = 'player/add_player.html' return render(request, template_name, {'form':form})
def agregar(request): if request.method == 'POST': print("post") form = PlayerForm(request.POST) if form.is_valid(): form.save() return redirect('listar:player_listar') else: print(form.errors) else: print("no post") form = PlayerForm() template_name = 'player/agregar.html' return render(request, template_name, {'form': form})
def agregarJugador(request): template_name = 'player/AgregarPlayer.html' if request.method == 'POST': form = PlayerForm(request.POST, request.FILES) if form.is_valid(): form.save() # j=Player.objects.create() # j.name=form.data.get('name') # j.nickname=form.data.get('nickname') # j.birthday=form.data.get('birthday') # j.age=form.data.get('age') # j.rut=form.data.get('rut') # j.email=form.data.get('email') # j.height=form.data.get('height') # j.weight=form.data.get('weight') # j.position=form.data.get('position') # j.team=Team.objects.get(id=form.data.get('team')) # j.picture=form.data.get('image') # j.save() return HttpResponseRedirect(reverse('listPlayer')) else: form = PlayerForm() return render(request, template_name, {'form': form})