6
Django设置默认表单值
我有一个模型如下: class TankJournal(models.Model): user = models.ForeignKey(User) tank = models.ForeignKey(TankProfile) ts = models.IntegerField(max_length=15) title = models.CharField(max_length=50) body = models.TextField() 我也有上述模型的模型形式,如下所示: class JournalForm(ModelForm): tank = forms.IntegerField(widget=forms.HiddenInput()) class Meta: model = TankJournal exclude = ('user','ts') 我想知道如何为该坦克隐藏字段设置默认值。这是我到目前为止显示/保存表格的功能: def addJournal(request, id=0): if not request.user.is_authenticated(): return HttpResponseRedirect('/') # checking if they own the tank from django.contrib.auth.models …