我已经有一些完全可用于此目的的代码,但我想进一步介绍。
我的实际代码列出了整个数据库注册表,让我对其进行编辑,但是要转到我希望的数据库注册表,我必须遍历它显示的庞大列表,这是我的代码:
def computer_update_view(request, pk, template_name='computer/computer_form.html'):
serial = get_object_or_404(Computer, pk=pk)
form = ComputerForm(request.POST or None, instance=serial)
context = {
'form':form
}
if form.is_valid():
form.save()
return redirect('computer:pc_list')
return render(request, template_name, context)
{% extends "base.html" %}
{% block content %}
<h2 xmlns="http://www.w3.org/1999/html"><a href="{% url 'computer:pc_list' %}">Network Admin</a></h2>
<ul>
<p> <button type="button"><a href="{% url 'computer:computer_new' %}">Add New</a></button></p>
{% for serie in object %}
<li>{{ serie.serial }}. {{ serie.name }} - ({{ serie.user_name }})
<a href="{% url 'computer:computer_edit' serie.serial %}">edit / </a>
</li>
{% endfor %}
</ul>
{% endblock %}
所以我想做的是让用户输入fox示例:用户输入序列“ 212125”(请注意,序列是数据库中的pk字段),然后只有该注册表显示要编辑。
我该怎么办?
答案 0 :(得分:0)
在forms.py中,编辑哪些字段显示在表单中。这可以通过类Meta
完成--more words and more words--
" Example of a string"
--Blah blah blah blah--
" This is an example of a string .
But this is a new line
It should all be foramted the same!"