Ticket #8795: django-8795.diff

File django-8795.diff, 1.2 KB (added by Alex Gaynor, 16 years ago)

Fixes problem with the test case to prove it

  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index 56e7f2a..f4036e5 100644
    a b class BaseModelForm(BaseForm):  
    210210
    211211    def validate_unique(self):
    212212        from django.db.models.fields import FieldDoesNotExist
    213         unique_checks = list(self.instance._meta.unique_together[:])
     213        unique_checks = [check for check in self.instance._meta.unique_together[:] if len([x for x in check if x in self.fields.keys()]) == len(check)]
    214214        form_errors = []
    215215       
    216216        # Make sure the unique checks apply to actual fields on the ModelForm
  • tests/modeltests/model_forms/models.py

    diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
    index dd6e25f..e3821de 100644
    a b False  
    11921192>>> form._errors
    11931193{'__all__': [u'Price with this Price and Quantity already exists.']}
    11941194
     1195>>> class PriceForm(ModelForm):
     1196...     class Meta:
     1197...         model = Price
     1198...         exclude = ('quantity',)
     1199>>> form = PriceForm({'price': '6.00'})
     1200>>> form.is_valid()
     1201True
     1202
    11951203# Choices on CharField and IntegerField
    11961204>>> class ArticleForm(ModelForm):
    11971205...     class Meta:
Back to Top