我有这个模型Django的现场验证的同型号
class Env(models.Model):
functional_count = models.PositiveIntegerField()
current_count = models.PositiveIntegerField()
现在我想functional_count
总是小于current_count
。
所以在创建,
def form_valid(self, form):
form.instance.current_count = 0
这是因为我initialization.Then我的Python代码时要current_count
从未允许current_count
上面去functional_count
。
问题出现在更新中。
class EnvUpdate(UpdateView):
model = Capacity.models.Envapps
fields = ['functional_count']
template_name_suffix = '_update_form'
所以我包括一个验证器?如果是的话,在哪里以及如何?
或其他选项是在get_success_url()
验证。
任何其他解决方案?
Django的表单和模型验证完全记录在案。你为什么不从这里开始:https://docs.djangoproject.com/en/1.6/ref/models/instances/#validating-objects –