Changeset 9341
- Timestamp:
- 11/05/08 13:47:44 (2 months ago)
- Files:
-
- django/trunk/django/forms/models.py (modified) (2 diffs)
- django/trunk/tests/modeltests/model_forms/models.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/forms/models.py
r9334 r9341 235 235 unique_checks = [] 236 236 for check in self.instance._meta.unique_together[:]: 237 fields_on_form = [field for field in check if field in self.cleaned_data and not self.cleaned_data[field] isNone]237 fields_on_form = [field for field in check if self.cleaned_data.get(field) is not None] 238 238 if len(fields_on_form) == len(check): 239 239 unique_checks.append(check) … … 249 249 # This is an extra field that's not on the ModelForm, ignore it 250 250 continue 251 if f.unique and name in self.cleaned_data and not self.cleaned_data[name] isNone:251 if f.unique and self.cleaned_data.get(name) is not None: 252 252 unique_checks.append((name,)) 253 253 django/trunk/tests/modeltests/model_forms/models.py
r9334 r9341 159 159 class Meta: 160 160 unique_together = ('title', 'author') 161 162 class ExplicitPK(models.Model): 163 key = models.CharField(max_length=20, primary_key=True) 164 desc = models.CharField(max_length=20, blank=True, unique=True) 165 class Meta: 166 unique_together = ('key', 'desc') 167 168 def __unicode__(self): 169 return self.key 161 170 162 171 __test__ = {'API_TESTS': """ … … 1248 1257 True 1249 1258 1259 # Test for primary_key being in the form and failing validation. 1260 >>> class ExplicitPKForm(ModelForm): 1261 ... class Meta: 1262 ... model = ExplicitPK 1263 ... fields = ('key', 'desc',) 1264 >>> form = ExplicitPKForm({'key': u'', 'desc': u'' }) 1265 >>> form.is_valid() 1266 False 1267 1268 # Ensure keys and blank character strings are tested for uniqueness. 1269 >>> form = ExplicitPKForm({'key': u'key1', 'desc': u''}) 1270 >>> form.is_valid() 1271 True 1272 >>> form.save() 1273 <ExplicitPK: key1> 1274 >>> form = ExplicitPKForm({'key': u'key1', 'desc': u''}) 1275 >>> form.is_valid() 1276 False 1277 >>> form.errors 1278 {'__all__': [u'Explicit pk with this Key and Desc already exists.'], 'key': [u'Explicit pk with this Key already exists.'], 'desc': [u'Explicit pk with this Desc already exists.']} 1279 1250 1280 # Choices on CharField and IntegerField 1251 1281 >>> class ArticleForm(ModelForm):
