我有一个需要来自其他模型的引用的表单。这里的例子。
我有models.py
class Employee(models.Model):
name = models.CharField(max_length=100)
class Inven(models.Model):
name = models.CharField(max_length=255)
sn = models.DecimalField(max_digits=20, decimal_places=0)
employee = models.ForeignKey(Employee, null=True, on_delete=models.SET_NULL, related_name='employee')
这是我的views.py
class InventoryListView(ListView):
context_object_name = 'inventorys'
model = models.Inventory
此处我的inven
template_form.html
<input type="text" name="name" maxlength="100" required="" id="id_name">
<input type="text" name="sn" maxlength="100" required="" id="id_sn">
<select>
{% for employee in employees %}
<option value="{{employee.pk}}">{{employee.name}}</option>
{% endfor %}
</select>
如何将员工字段作为employee
模型中的选择列表?...