Changeset 8854
- Timestamp:
- 09/02/08 09:20:11 (3 months ago)
- Files:
-
- django/trunk/django/forms/models.py (modified) (1 diff)
- django/trunk/tests/modeltests/model_forms/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/forms/models.py
r8823 r8854 211 211 def validate_unique(self): 212 212 from django.db.models.fields import FieldDoesNotExist 213 unique_checks = list(self.instance._meta.unique_together[:]) 213 214 # Gather a list of checks to perform. Since this is a ModelForm, some 215 # fields may have been excluded; we can't perform a unique check on a 216 # form that is missing fields involved in that check. 217 unique_checks = [] 218 for check in self.instance._meta.unique_together[:]: 219 fields_on_form = [field for field in check if field in self.fields] 220 if len(fields_on_form) == len(check): 221 unique_checks.append(check) 222 214 223 form_errors = [] 215 224 216 # Make sure the unique checks apply to actual fields on the ModelForm 225 # Gather a list of checks for fields declared as unique and add them to 226 # the list of checks. Again, skip fields not on the form. 217 227 for name, field in self.fields.items(): 218 228 try: django/trunk/tests/modeltests/model_forms/models.py
r8842 r8854 1193 1193 {'__all__': [u'Price with this Price and Quantity already exists.']} 1194 1194 1195 >>> class PriceForm(ModelForm): 1196 ... class Meta: 1197 ... model = Price 1198 ... exclude = ('quantity',) 1199 >>> form = PriceForm({'price': '6.00'}) 1200 >>> form.is_valid() 1201 True 1202 1195 1203 # Choices on CharField and IntegerField 1196 1204 >>> class ArticleForm(ModelForm):
