Discussion:
getting data from a stored procedure.
aramis1212 via Django REST framework
2018-08-22 00:47:12 UTC
Permalink
I've taken the tutorial and can now create an api to post a from that will
create a line in my database.

now I have view that uses a stored proc to return approved or nor approved
after I pass 5 integers in and expect 1 to be returned. how do I turn that
into an api? I am thinking viewsets will no longer work.

I have another stored procedure that returns an integer when called that
has no input parameters.

In both cases I want to continue using stored procedures.


def permission_check(request):
# If this is a POST request then process the Form data
if request.method == 'POST' :
chk_permission_form = ChkPermissionForm(request.POST)
outpermitted = 0
if chk_permission_form.is_valid():
cursor = connection.cursor()

cursor.callproc('chkpermission',[chk_permission_form.cleaned_data['pica_number'],
chk_permission_form.cleaned_data['freetradezone']
,chk_permission_form.cleaned_data['divisioncode']
,chk_permission_form.cleaned_data['gwp'],chk_permission_form.cleaned_data['taskid']])
result_set = cursor.fetchall()
cursor.close()
if result_set[0][0] == 1:
sometext = 'approved'
else:
sometext = 'declined'
return render(request, 'picamaintenance/permission_check.html',
context = {'sometext': sometext})
#return render(request, 'picamaintenance/permission_results.html',
context)
# If this is a GET (or any other method) create the default form.
else:
#proposed_renewal_date = datetime.date.today() +
datetime.timedelta(weeks=3)
chk_permission_form = ChkPermissionForm()
context = {
'form': chk_permission_form,
}
return render(request, 'picamaintenance/permission_check.html', context)
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...