3
考虑以下Django模型:Django的1.1形式,模式和隐藏领域
class Host(models.Model):
# This is the hostname only
name = models.CharField(max_length=255)
class Url(models.Model):
# The complete url
url = models.CharField(max_length=255, db_index=True, unique=True)
# A foreign key identifying the host of this url
# (e.g. for http://www.example.com/index.html it will
# point to a record in Host containing 'www.example.com'
host = models.ForeignKey(Host, db_index=True)
我也有这种形式:
class UrlForm(forms.ModelForm):
class Meta:
model = Urls
的问题是:我想计算的价值主机字段自动, ,所以我不希望它出现在网页上显示的HTML表单中。
如果我使用“排除”从表格中省略该字段,那么我怎样才能使用表格将信息 保存在数据库中(这需要主机字段存在)?