Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress validation errors of descendent inlines of deleted forms
fixes #101
- Loading branch information
Showing
6 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
20 changes: 20 additions & 0 deletions
20
nested_admin/tests/nested_delete_validationerrors/admin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.contrib import admin | ||
import nested_admin | ||
from .models import Parent, Child, GrandChild | ||
|
||
|
||
class GrandChildInline(nested_admin.NestedStackedInline): | ||
model = GrandChild | ||
extra = 0 | ||
min_num = 1 | ||
|
||
|
||
class ChildInline(nested_admin.NestedStackedInline): | ||
model = Child | ||
inlines = [GrandChildInline] | ||
extra = 0 | ||
|
||
|
||
@admin.register(Parent) | ||
class ParentAdmin(nested_admin.NestedModelAdmin): | ||
inlines = [ChildInline] |
39 changes: 39 additions & 0 deletions
39
nested_admin/tests/nested_delete_validationerrors/models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models | ||
from django.db.models import ForeignKey, CASCADE | ||
from nested_admin.tests.compat import python_2_unicode_compatible | ||
|
||
|
||
@python_2_unicode_compatible | ||
class Parent(models.Model): | ||
name = models.CharField(max_length=128) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
@python_2_unicode_compatible | ||
class Child(models.Model): | ||
name = models.CharField(max_length=128) | ||
parent = ForeignKey(Parent, on_delete=CASCADE, related_name='children') | ||
position = models.PositiveIntegerField() | ||
|
||
class Meta: | ||
ordering = ['position'] | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
@python_2_unicode_compatible | ||
class GrandChild(models.Model): | ||
name = models.CharField(max_length=128) | ||
parent = ForeignKey(Child, on_delete=CASCADE, related_name='children') | ||
position = models.PositiveIntegerField() | ||
|
||
class Meta: | ||
ordering = ['position'] | ||
|
||
def __str__(self): | ||
return self.name |
37 changes: 37 additions & 0 deletions
37
nested_admin/tests/nested_delete_validationerrors/tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import time | ||
from unittest import SkipTest | ||
|
||
from django.conf import settings | ||
|
||
from nested_admin.tests.base import BaseNestedAdminTestCase | ||
from .models import Parent, Child, GrandChild | ||
|
||
|
||
class TestDeleteNestedInlineMinNumRequirement(BaseNestedAdminTestCase): | ||
|
||
root_model = Parent | ||
nested_models = (Child, GrandChild) | ||
|
||
def test_min_num_delete_bug(self): | ||
"""It should be possible to delete inlines, even if min_num requirement not met""" | ||
rhea = Parent.objects.create(name='Rhea') | ||
poseidon = Child.objects.create(name='Poseidon', parent=rhea, position=0) | ||
zeus = Child.objects.create(name='Zeus', parent=rhea, position=1) | ||
demeter = Child.objects.create(name='Demeter', parent=rhea, position=2) | ||
|
||
GrandChild.objects.create(name='Apollo', parent=zeus, position=0) | ||
GrandChild.objects.create(name='Persephone', parent=demeter, position=0) | ||
|
||
self.load_admin(rhea) | ||
self.delete_inline([0]) | ||
self.save_form() | ||
|
||
validation_errors = self.selenium.execute_script( | ||
"return $('ul.errorlist li').length") | ||
|
||
self.assertEqual( | ||
0, validation_errors, "Save should have completed without validation errors") | ||
|
||
children = Child.objects.filter(parent=rhea) | ||
self.assertNotEqual(3, len(children), "Child with empty grandchild was not deleted") | ||
self.assertEqual(2, len(children)) |