DJANG Views : CURD

DJANGO


Add New Record

def addstocknews(request):
    if request.method == 'POST':
        form = stock_news_f(request.POST)
        # check whether it's valid:
        if form.is_valid():
            form.save(commit=True)
            form = stock_news_f()

    else:
        form = stock_news_f()

    return render(request, 'wlist/addstocknews.html', {'form': form})

 

Edit Record

def editdocument(request , doc_id):
    doc_data = doc_data_m.objects.get(id=doc_id)
    if request.method == 'POST':
        form = doc_data_f(request.POST,instance=doc_data)
        if form.is_valid():
            form.save(commit=True)
            return HttpResponseRedirect('/doc/')

    # if a GET (or any other method) we'll create a blank form
    else:
        
        form = doc_data_f(instance = doc_data)

    return render(request, 'document/editdoc.html', {'form': form,'docid':doc_id})

 

            Related
DJANG Views : CURD