我对 django 有疑问:
models.py:
SUSPEND_TIME = (
('0', '0'),
('10', '10'),
('15', '15'),
('20', '20'),
class Order(models.Model):
user = models.ForeignKey(User)
city = models.CharField(max_length=20)
...
processed = models.BooleanField(default=False)
suspend_time = models.CharField(max_length=2, choices=SUSPEND_TIME, default='0')
..
表格.py:
class OrderForm(forms.ModelForm):
class Meta:
model = Order
fields = ('suspend_time', 'processed')
视图.py:
try:
order = Order.objects.get(id=order_id)
except Order.DoesNotExist:
order = None
else:
form = OrderForm(request.POST, instance=order)
if form.is_valid():
form.save()
....
然后我发送 ajax 请求以仅使用"processed"
参数更新实例。如果我不发送
如果请求包含我
form.is_valid
总是
不明白为什么?有默认值..和顺序。总是有一些或其他的选择。
为什么在is之后,其他字段 都有正常值。 False
"suspend_time" !
{'suspend_time': 'some_value' ...}
form.is_valid
True
suspend_time
suspend_time
value: default
form = OrderForm(request.POST, instance=order)
form['suspend_time'].value()
None
(city, processed)