Commit d4df21c
committed
Allow use of can_delete flag directly in inline definition
The previous README had instructions about preventing the deletion of
inlined models by overriding the `has_delete_permission` method on a
custom subclass of the appropriate `StackedInline` or `TabularInline`
class, and then passing that subclass as the `admin_class` option of
`inline_reverse`. However, that method no longer works with newer
versions of Django (at least with Django 4.2 and later).
This commit updates the `ReverseInlineModelAdmin` class to determine
`can_delete` in the same way that Django's `InlineModelAdmin` currently
does, and then passes that into the custom formset factory. In that
way, consumers of this library can simply set the `can_delete` option
directly on their `inline_reverse` specification without subclassing one
of the built-in `InlineModelAdmin` implementations.
Note that this approach was necessary because the custom formset factory
in `django_reverse_admin` lives outside of the `ReverseInlineModelAdmin`
class, and doesn't have access to the parent class' `can_delete`
property and `has_delete_permission` method.1 parent 6fae3c4 commit d4df21c
File tree
4 files changed
+24
-17
lines changed- django_reverse_admin
- tests/polls
4 files changed
+24
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | | - | |
110 | | - | |
| 108 | + | |
111 | 109 | | |
112 | 110 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | 111 | | |
124 | 112 | | |
125 | 113 | | |
126 | 114 | | |
127 | 115 | | |
128 | 116 | | |
129 | 117 | | |
130 | | - | |
| 118 | + | |
131 | 119 | | |
132 | 120 | | |
133 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | | - | |
| 76 | + | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| |||
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
86 | | - | |
| 87 | + | |
| 88 | + | |
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
| |||
129 | 131 | | |
130 | 132 | | |
131 | 133 | | |
| 134 | + | |
132 | 135 | | |
133 | 136 | | |
134 | 137 | | |
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
| 141 | + | |
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
44 | 54 | | |
45 | 55 | | |
46 | 56 | | |
| |||
74 | 84 | | |
75 | 85 | | |
76 | 86 | | |
| 87 | + | |
77 | 88 | | |
78 | 89 | | |
79 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
| |||
0 commit comments