I have a Django model that looks like this.
class Solution(models.Model): ''' Represents a solution to a specific problem. ''' name = models.CharField(max_length=50) problem = models.ForeignKey(Problem) description = models.TextField(blank=True) date = models.DateTimeField(auto_now_add=True) class Meta: unique_together = ("name", "problem")
I use the form to add models that look like this:
class SolutionForm(forms.ModelForm): class Meta: model = Solution exclude = ['problem']
My problem is that SolutionForm does not check the Solution unique_together and thus returns an IntegrityError when trying to save the form. I know that I could use validate_unique to manually verify this, but I was wondering if there is a way to catch this in the validation form and automatically return the form error.
Thank.
django validation modelform
sttwister Jan 26 '10 at 17:01 2010-01-26 17:01
source share