Django version 1.8.16 pyodbc Version: 3.0.11b16
I have been trying to make a view/submit form for a project. The basic aim I need to achieve is to view and edit/save the data in the form using stored procedure in MS SQL Server 2014. I am able to use stored procedure in the view page but have not been able to do so with the edit item and add a new item .
models.py
class procedures():
def view_patientsp(self, patid):
cursor = connection.cursor()
ret = cursor.execute("EXEC PR_PRES_viewpatient @uid=? ", (patid))
cursor.close()
return ret
class Patient(models.Model):
patientid = models.AutoField(db_column='PatientID', primary_key=True)
pyear = models.DecimalField(db_column='Pyear', max_digits=10, decimal_places=0, blank=True, null=True)
dref = models.DecimalField(db_column='DRef', max_digits=10, decimal_places=0, blank=True, null=True)
title = models.TextField(db_column='Title', blank=True, null=True)
fname = models.TextField(db_column='FName', blank=True, null=True)
lname = models.TextField(db_column='LName', blank=True, null=True)
dob = models.DateTimeField(db_column='DOB', blank=True, null=True)
pamonth = models.TextField(db_column='PAMonth', blank=True, null=True)
payear = models.TextField(db_column='PAYear', blank=True, null=True)
padays = models.TextField(db_column='PADays', blank=True, null=True)
sex = models.TextField(db_column='Sex', blank=True, null=True)
views.py
def view_patient(request):
if request.method == 'POST':
form = viewpatientform(request.POST)
return render(request, 'lis/view.html', {'form': form})
else:
form = viewpatientform()
if form.is_valid():
procedure = procedures()
ret = procedure.view_patientsp(request.POST['fields'])
return render_to_response('lis/view.html', {'form': form})
urls.py
urlpatterns = [
url(r'^$', views.pat_list, name='index'),
url(r'^view/(?P<patid>\d+/)$', views.view_patient, name='viewpatient'), ]
view.html
{% block body %}
{% load materializecss %}
{{ form|materializecss }}
<button type="submit" class="btn btn-primary">Submit</button>
{% endblock %}