我有一个公司模型:
class Company(models.Model):
companyId = models.IntegerField(unique=True, blank = True, null = True )
address = models.ForeignKey(Address, blank = True, null = True )
...
和地址模型:
class Address(models.Model):
address1 = models.CharField (max_length=300, blank = True, null = True)
...
我需要为外键创建一个可编辑的表单,这是我的代码:
class CompanyForm(forms.ModelForm):
address = forms.CharField(label='Address', max_length=500, required=False)
...
该表单的视图是
<div class="control-group">
<label class="control-label" for="id_address">{{ form.address.label }}</label>
<div class="controls">
{{ form.instance.address.address1 }}
</div>
</div>
地址和标签已显示,但我无法修改该字段。实际使该字段可编辑的方法是什么?任何帮助表示赞赏!