在我的models.py
class Alert(models.Model):
user = models.CharField(max_length=30, blank=True)
a = models.IntegerField(blank=True)
def __unicode__(self):
return "'%s' at %s" % (self.user)
在我的 forms.py 中:
class AlertForm(forms.ModelForm):
class Meta:
model=Alert
fields = ('a','user')
widgets = {
'user': forms.HiddenInput()
}
AlertCountFormset = modelformset_factory(Alert,
form = AlertForm)
在我的views.py中:
def profile_setting(request, slug):
if request.method == 'GET':
form = AlertForm(request.POST)
if form.is_valid():
alert_form = form.save(commit=False)
alert_form.user = request.user.username
alert_form.save() # Here i am getting the error
return HttpResponseRedirect('/user/list')
extra_context = {
'form': AlertForm()
}
return direct_to_template(request,'users/profile_setting.html',
extra_context)
我正在尝试填写 Django 模型表单,但我正在关注error
我发表评论的位置:
events_alertcount.a may not be NULL
这是什么?即使将它放在它null=True
的字段中也会a
显示相同的错误。是不是我的有什么问题forms.py or models.py
?