擅长:python、mysql、java
<p>Clean data在is_有效之前运行,因为Clean是django运行以验证表单的许多方法之一</p>
<p>因为您只清洁一个区域,请使用“清洁”来清洁此区域</p>
<pre><code>class BokningForm(ModelForm)
...
def clean_pumpstart(self):
data = self.cleaned_data['pumpStart']
data = datetime.strptime(data , "%Y-%m-%d %H:%M")
return data
</code></pre>
<p>在你看来,也许这可以锻炼身体</p>
^{pr2}$
<p><strong>编辑</strong>:在其他帖子中得到了一些有用的信息。。。尝试在模型内部使用clean方法,看起来这是先运行的</p>
<pre><code>class Bokning(models.Model):
def clean(self):
...
</code></pre>
<p>来源:<a href="https://stackoverflow.com/questions/47510752/django-model-clean-method-called-before-form-clean">Django: Model clean method called before form clean</a></p>