Exemplo n.º 1
0
def update(request,id):
    update=Students.objects.get(id=id)
    form=StudentsForm(request.POST,instance=update)
    if form.is_valid():
        form.save()
        messages.success(request,"Student record is updated")
        return render(request,'edit.html',{'Students':update})
Exemplo n.º 2
0
def update(request, id):
    context = {}
    obj = Students.objects.get(id=id)
    form = StudentsForm(request.POST, instance=obj)
    if form.is_valid():
        form.save()
        return redirect("/view")
    context["form"] = form
    return render(request, "update.html", context)
Exemplo n.º 3
0
def std(request):
    # dictionary for initial data with
    # field names as keys
    context = {}

    # add the dictionary during initialization
    form = StudentsForm(request.POST or None)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect("/list_view")
    context['form'] = form
    return render(request, "create_view.html", context)
Exemplo n.º 4
0
def update_view(request, id):
    # dictionary for initial data with
    # field names as keys
    context = {}

    # fetch the object related to passed id
    obj = get_object_or_404(Students, id=id)

    # pass the object as instance in form
    form = StudentsForm(request.POST or None, instance=obj)

    # save the data from the form and
    # redirect to detail_view
    if form.is_valid():
        form.save()
        return HttpResponseRedirect("/list_view")

        # add form dictionary to context
    context["form"] = form

    return render(request, "update_view.html", context)
Exemplo n.º 5
0
def StudentsAdd(request):
    form = StudentsForm()
    if request.method == 'POST':
        form = StudentsForm(request.POST)
        if form.is_valid():
            student = form.save(commit=False)
            if "profile_pic" in request.FILES:
                student.profile_pic = request.FILES['profile_pic']
            student.save()
            messages.success(request, ("You have Registered a Students.."))
            return redirect('/')
    else:
        form = StudentsForm()
    return render(request,'students/students_add.html',context={'form':form})
Exemplo n.º 6
0
def std(request):
    if request.method == "POST":
        form = StudentsForm(request.POST)
        if form.is_valid():
            try:
                form.save()
                return redirect('/view')
            except:
                pass
    else:
        form = StudentsForm()
    return render(request, 'index.html', {'form': form})
Exemplo n.º 7
0
def update(request, id):

        student = get_object_or_404(Students, id=id)

        if request.method == 'GET':
                form = StudentsForm(instance=student)
                return redirect("/view")

        else:
                form = StudentsForm(request.POST, instance=student)
                form.save()
                return redirect("/view")
Exemplo n.º 8
0
def update(request, id):
    if request.method == "GET":
        if id == 0:
            form = StudentsForm()
        else:
            students = Students.objects.get(id=id)
            form = StudentsForm(instance=students)
        return render(request, "edit.html", {'form': form})
    else:
        if id == 0:
            form = StudentsForm(request.POST)
        else:
            students = Students.objects.get(id=id)
            form = StudentsForm(request.POST, instance=students)
        if form.is_valid():
            form.save()
        return redirect('/view')