我通过重写validate_unique()ModelForm 的方法解决了相同的问题:
def validate_unique(self): exclude = self._get_validation_exclusions() exclude.remove('problem') # allow checking against the missing attribute try: self.instance.validate_unique(exclude=exclude) except ValidationError, e: self._update_errors(e.message_dict)现在,我只是始终确保表单上未提供的属性仍然可用,例如
instance=Solution(problem=some_problem)在初始化程序上。



