발권 시스템을 만들려고합니다. 내가 원하는 것은 상태 드롭 다운 목록을 변경할 때 데이터베이스의 티켓 상태를 업데이트해야한다는 것입니다. 또한 같은 페이지에서 업데이트하고보고 싶습니다. 가능한 모든 통찰력?django : onsubmit 드롭 다운시 데이터베이스 업데이트
forms.py이 같은
class ViewForm(forms.Form):
statuses = [
('In Progress', 'In Progress'),
('On Hold', 'On Hold'),
('Done', 'Done'),
('ForQA', 'ForQA'),
('QAPassed', 'QAPassed'),
('QARevs', 'QARevs'),
]
status = forms.ChoiceField(label='Status', required=True, choices=statuses, widget=forms.Select(attrs={'onchange': 'actionform.submit();'}))
views.py
def view_sheet(request, project_id):
project = Project.objects.get(pk=project_id)
tickets = Ticket.objects.filter(project=project_id)
form = ViewForm()
context = {
'project': project,
'tickets': tickets,
'form': form,
}
return render(request, 'project/sheet/view.html', context)
view.html
<div class="tracker-sheet">
<div class="project-name">
<h1>{{project.name}}</h1>
</div>
<div class="actions">
<a href="{% url 'add_ticket' project.id %}">
<button type="submit">New Ticket</button>
</a>
</div >
<div class="tracker-table">
<table>
<tr>
<th>Total Worked</th>
<th>Status</th>
<th>Status Date</th>
<th>Received</th>
<th>Due Date</th>
<th>Agent</th>
<th>Sub Type</th>
<th>CID</th>
<th>Link</th>
<th>Task Description</th>
<th>Server</th>
<th>Qty</th>
<th>Info</th>
</tr>
{% for ticket in tickets %}
<tr>
<td><span class="table-constant"></span></td>
{% for field in form %}
<td>{{field}}</td> <!-- Status dropdown list -->
{% endfor %}
<td><span class="table-constant">{{ticket.status_date}}</span></td>
</form>
<td><span class="table-constant">{{ticket.received}}</span></td>
<td><span class="table-constant">{{ticket.due_date}}</span></td>
<td><span class="table-constant"></span></td>
<td><span class="table-constant">{{ticket.sub_type}}</span></td>
<td><span class="table-vary"></span></td>
<td><span class="table-constant">{{ticket.link}}</span></td>
<td><input type="submit" value="{{ticket.task_description}}"</td>
<td><span class="table-constant"></span></td>
<td><span class="table-constant">{{ticket.qty}}</span></td>
<td></td>
</tr>
{% endfor %}
</table>
</div>
이것은 매우 자세하고 철저한 대답입니다. – noes1s
감사합니다. 나는 그것이 받아 들여지지 않은 이유를 궁금하게 생각한다? –
좋은 예입니다. 또한 OP, 사용자가 로그인되어 있고 컨텐츠를 편집 할 수있는 적절한 권한이 있는지 확인할 수 있습니다 :) – ppython