こんにちは私は比較的新しいDjangoです。私はユーザーが詳細を入力するためのタイムシートを持っています、送信ボタンが選択されると、それらの埋められたフィールドのデータはデータベースに保存されます。しかし、私はなぜ私のdoesntの作品が分かりません。値が保存されると、値が取得され、別のhtmlファイルのテーブルに表示されます。既にファズルとしてデータベースに値を保存するDjango
timesheet.html
{% extends 'hrfinance/base.html' %}
{% block title %} Timesheet {% endblock %}
{% block link %}
{% load staticfiles %}
<link rel="stylesheet" href="{% static 'hrfinance/css/timesheet.css' %}"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
/*to ensure that all the textbox and checkbox have been filled before users can submit*/
function validation() {
/*ensure start date has been entered*/
if (!$('#studentid').val().trim()) {
alert('Please fill in student ID field');
}
/*ensure start date has been entered*/
if (!$('#studentname').val().trim()) {
alert('Please fill in student name field');
}
/*ensure start date has been entered*/
if (!$('#sdate').val().trim()) {
alert('Please fill in start date field');
}
/*ensure end date has been entered*/
if (!$('#edate').val().trim()) {
alert('Please fill in end date field');
}
/*ensure checkbox has been ticked*/
if (!$('#agree').is(':checked')) {
alert('Please indicate that you have satisfied all the requirements');
}
else{
console.log('ok')
}
}
</script>
{% endblock %}
{% block body %}
<div class="sub-bar">
<p>Submit Timesheet</p>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<form onsubmit="return validation()">
<div class="content-wrapper">
<div class="sub-content">
<div>
<p>Student ID: {{timesheet.studentID}}</p>
<input id="sid" type="field" name="studentid">
</div>
</div>
<div class="sub-content">
<div>
<p>Student Name: {{timesheet.studentName}}</p>
<input id="sname" type="field" name="studentname">
</div>
</div>
<div class="sub-content">
<div>
<p>Start Date: {{timesheet.startDate}}</p>
<input id="sdate" type="date" name="startdate">
</div>
</div>
<div class="sub-content">
<div>
<p>End Date: {{timesheet.endDate}}</p>
<input id="edate" type="date" name="enddate">
</div>
</div>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="end-content">
<div class="center-align">
<div class="checklist">
<p>By checking this box I agree that I have satisfied all requirements to continue receiving my scholarship
allowance.</p>
<input id="agree" type="checkbox" name="checkbox" class="tick-att">
</div>
<br>
<div class="align-right">
<input type="submit" class="button" name="submit" value="submit" >
</div>
</div>
</div>
</from>
{% endblock %}
views.py
def timesheet(request):
return render(request, 'hrfinance/timesheet.html')
models.py
#consists of all the details in the timesheet
class Timesheet(models.Model):
studentID = models.CharField("Student ID", max_length=8, primary_key=True, default="")
studentName = models.CharField("Student Name", max_length=500, default="")
startDate = models.DateField("Start Date", max_length=8)
endDate = models.DateField("End Date", max_length=8)
def __str__(self):
return self.studentID
これはすべてあなたのviews.pyにありますか? – zaidfazil
@FazilZaidはい... –
このリンクを見てください... https://docs.djangoproject.com/ja/1.11/topics/forms/ – zaidfazil