Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added SortableHiddenMixin to copy a useful shortcut from Grappelli
- Loading branch information
1 parent
d3749e2
commit 4e873b0
Showing
4 changed files
with
48 additions
and
1 deletion.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.forms.widgets import HiddenInput | ||
|
||
|
||
class SortableHiddenMixin(object): | ||
""" | ||
Enables inline sorting and hides the sortable field. | ||
By default it assumes the field name is ``position``. This can be | ||
overridden by setting the ``sortable_field_name`` attribute to a | ||
different value. | ||
""" | ||
sortable_field_name = "position" | ||
|
||
def formfield_for_dbfield(self, db_field, **kwargs): | ||
if db_field.name == self.sortable_field_name: | ||
kwargs["widget"] = HiddenInput() | ||
return super(SortableHiddenMixin, self).formfield_for_dbfield( | ||
db_field, **kwargs) |
4e873b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice feature, please mention in docs how to call it properly:
nested_admin.**forms**.SortableHiddenMixin