我有从模型生成的表格
class UserProfile(models.Model):
company = models.ForeignKey(Company)
user = models.OneToOneField(User)
department = models.CharField(max_length=100)
position = models.CharField(max_length=100)
class UserProfileForm(ModelForm):
company_id = ModelChoiceField(queryset=Company.objects.all(),
widget=HiddenInput())
class Meta:
model = UserProfile
exclude = ('user')
但它不起作用,并且 company_id 保持可见选择字段。如何使用公司 ID 创建隐藏字段?