-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: max_num show/hide bug with recursively nested models
fixes #230
- Loading branch information
Showing
12 changed files
with
124 additions
and
30 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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.
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,26 @@ | ||
from django.contrib import admin | ||
import nested_admin | ||
from .models import MenuItem | ||
|
||
|
||
class Level2Inline(nested_admin.NestedTabularInline): | ||
model = MenuItem | ||
extra = 0 | ||
min_num = 0 | ||
title = "Level 2" | ||
|
||
|
||
class Level1Inline(nested_admin.NestedTabularInline): | ||
model = MenuItem | ||
inlines = [Level2Inline] | ||
extra = 0 | ||
min_num = 1 | ||
max_num = 2 | ||
title = "Level 1" | ||
|
||
|
||
@admin.register(MenuItem) | ||
class ParentAdmin(nested_admin.NestedModelAdmin): | ||
inlines = [Level1Inline] | ||
title = "Menu" | ||
fields = ["label"] |
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,14 @@ | ||
from django.db import models | ||
from django.db.models import ForeignKey, CASCADE | ||
|
||
|
||
class MenuItem(models.Model): | ||
label = models.CharField(max_length=255) | ||
parent = ForeignKey("MenuItem", related_name="children", on_delete=CASCADE, null=True) | ||
position = models.PositiveIntegerField(default=0) | ||
|
||
class Meta: | ||
ordering = ["position"] | ||
|
||
def __str__(self): | ||
return self.name |
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,42 @@ | ||
# from unittest import SkipTest | ||
|
||
# from django.conf import settings | ||
|
||
from nested_admin.tests.base import BaseNestedAdminTestCase | ||
from .models import MenuItem | ||
|
||
|
||
class TestRecursiveNesting(BaseNestedAdminTestCase): | ||
|
||
root_model = MenuItem | ||
nested_models = (MenuItem, MenuItem) | ||
|
||
def test_max_num_nested_add_handlers_hide(self): | ||
self.load_admin(self.root_model) | ||
level1_add_handler = self.selenium.execute_script( | ||
""" | ||
return django.jQuery( | ||
'.djn-add-handler.djn-model-nested_recursive-menuitem.djn-level-1' | ||
)[0]""" | ||
) | ||
level2_add_handler = self.selenium.execute_script( | ||
""" | ||
return django.jQuery( | ||
'.djn-add-handler.djn-model-nested_recursive-menuitem.djn-level-2' | ||
)[0]""" | ||
) | ||
self.add_inline() | ||
self.wait_until_element_is( | ||
level1_add_handler, | ||
":not(:visible)", | ||
"handler did not hide after max_num reached", | ||
) | ||
assert ( | ||
level2_add_handler.is_displayed() is True | ||
), "level2 add handler should not be hidden" | ||
self.remove_inline([0]) | ||
self.wait_until_element_is( | ||
level1_add_handler, | ||
":visible", | ||
"handler did not unhide after max_num inline removed", | ||
) |