Exemplo n.º 1
0
def new_actor(request):
    if request.method == "POST":
        form = ActorForm(request.POST)
        if form.is_valid():
            if form.save():
                return redirect("/actors")
    else:
        form = ActorForm()
    data = {'form': form}
    return render(request, "actors/new_actor.html", data)
Exemplo n.º 2
0
def edit_actor(request, actor_id):
    actor = Actor.objects.get(id=actor_id)
    if request.method == "POST":
        form = ActorForm(request.POST, instance=actor)
        if form.is_valid():
            if form.save():
                return redirect("/actors/{}".format(actor_id))

        else:
            form = ActorForm(instance=actor)
    data = {"actor": actor, "form": form}
    return render(request, "actors/edit_actor.html", data)
Exemplo n.º 3
0
def new_actor(request):
	# If the user is submitting the form
	if request.method == "POST":

		# Get the instance of the form filled with the submitted data
		form = ActorForm(request.POST)

		# Django will check the form's validity for you
		if form.is_valid():

			# Saving the form will create a new Genre object
			if form.save():
				# After saving, redirect the user back to the index page
				return redirect("/actors")

	# Else if the user is looking at the form page
	else:
		form = ActorForm()
	data = {'form': form}
	return render(request, "new_actor.html", data)
Exemplo n.º 4
0
def edit_actor(request, actor_id):
	# Similar to the the detail view, we have to find the existing genre we are editing
	actor = Actor.objects.get(id=actor_id)

	# We still check to see if we are submitting the form
	if request.method == "POST":
		# We prefill the form by passing 'instance', which is the specific
		# object we are editing
		form = ActorForm(request.POST, instance=actor)
		if form.is_valid():
			if form.save():
				return redirect("/actors/{}".format(actor_id))

	# Or just viewing the form
	else:
		# We prefill the form by passing 'instance', which is the specific
		# object we are editing
		form = ActorForm(instance=actor)
	data = {"actor": actor, "form": form}
	return render(request, "edit_actor.html", data)