diff --git a/django/forms/models.py b/django/forms/models.py
index 912bdf3..0c8c5df 100644
a
|
b
|
class BaseModelForm(BaseForm):
|
342 | 342 | Calls the instance's validate_unique() method and updates the form's |
343 | 343 | validation errors if any were raised. |
344 | 344 | """ |
345 | | exclude = self._get_validation_exclusions() |
346 | 345 | try: |
347 | | self.instance.validate_unique(exclude=exclude) |
| 346 | self.instance.validate_unique() |
348 | 347 | except ValidationError, e: |
349 | 348 | self._update_errors(e.message_dict) |
350 | 349 | |
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
index 7d6cab3..80ff365 100644
a
|
b
|
class FoodDeliveryAdmin(admin.ModelAdmin):
|
704 | 704 | list_display=('reference', 'driver', 'restaurant') |
705 | 705 | list_editable = ('driver', 'restaurant') |
706 | 706 | |
| 707 | class UniqueTogether(models.Model): |
| 708 | t1 = models.CharField(max_length=255, blank=True, null=True) |
| 709 | t2 = models.CharField(max_length=255, blank=True, null=True) |
| 710 | t3 = models.CharField(max_length=255, blank=True, null=True) |
| 711 | |
| 712 | class Meta: |
| 713 | unique_together = ['t1','t2','t3'] |
| 714 | |
| 715 | class UniqueTogetherAdmin(admin.ModelAdmin): |
| 716 | list_display = ['t3', 't1', 't2'] |
| 717 | list_editable = ['t1', 't2',] |
| 718 | |
707 | 719 | |
708 | 720 | admin.site.register(Article, ArticleAdmin) |
709 | 721 | admin.site.register(CustomArticle, CustomArticleAdmin) |
… |
… |
admin.site.register(WorkHour, WorkHourAdmin)
|
743 | 755 | admin.site.register(Reservation) |
744 | 756 | admin.site.register(FoodDelivery, FoodDeliveryAdmin) |
745 | 757 | admin.site.register(RowLevelChangePermissionModel, RowLevelChangePermissionModelAdmin) |
| 758 | admin.site.register(UniqueTogether, UniqueTogetherAdmin) |
746 | 759 | |
747 | 760 | # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. |
748 | 761 | # That way we cover all four cases: |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 642186e..da04137 100644
a
|
b
|
from models import (Article, BarAccount, CustomArticle, EmptyModel,
|
36 | 36 | Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, |
37 | 37 | Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee, |
38 | 38 | Question, Answer, Inquisition, Actor, FoodDelivery, |
39 | | RowLevelChangePermissionModel) |
| 39 | RowLevelChangePermissionModel, UniqueTogether) |
40 | 40 | |
41 | 41 | |
42 | 42 | class AdminViewBasicTest(TestCase): |
… |
… |
class AdminViewListEditable(TestCase):
|
1373 | 1373 | # 1 select per object = 3 selects |
1374 | 1374 | self.assertEqual(response.content.count("<select"), 4) |
1375 | 1375 | |
| 1376 | def test_partial_unique_together(self): |
| 1377 | """ Ensure that no IntegrityError is raised when editing some (but |
| 1378 | not all) of the values specified as unique_together. Refs #13091. |
| 1379 | """ |
| 1380 | UniqueTogether.objects.create(t1='a', t2='b', t3='c') |
| 1381 | UniqueTogether.objects.create(t1='b', t2='b', t3='a') |
| 1382 | UniqueTogether.objects.create(t1='c', t2='a', t3='c') |
| 1383 | data = { |
| 1384 | "form-TOTAL_FORMS": "3", |
| 1385 | "form-INITIAL_FORMS": "3", |
| 1386 | "form-MAX_NUM_FORMS": "0", |
| 1387 | |
| 1388 | "form-0-t1": "a", |
| 1389 | "form-0-t2": "b", |
| 1390 | "form-0-t3": "c", |
| 1391 | "form-0-id": "1", |
| 1392 | |
| 1393 | "form-1-t1": "a", |
| 1394 | "form-1-t2": "b", |
| 1395 | "form-1-t3": "c", |
| 1396 | "form-1-id": "2", |
| 1397 | |
| 1398 | "form-2-t1": "a", |
| 1399 | "form-2-t2": "b", |
| 1400 | "form-2-t3": "c", |
| 1401 | "form-2-id": "3", |
| 1402 | |
| 1403 | "_save": "Save", |
| 1404 | } |
| 1405 | response = self.client.post('/test_admin/admin/admin_views/uniquetogether/', data) |
| 1406 | self.assertContains(response, 'Please correct the errors below.') |
| 1407 | self.assertContains(response, 'Unique together with this T1, T2 and T3 already exists.') |
| 1408 | |
1376 | 1409 | def test_post_messages(self): |
1377 | 1410 | # Ticket 12707: Saving inline editable should not show admin |
1378 | 1411 | # action warnings |