Skip to content

Fix: bug when order value is zero #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adminsortable/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = (2, 3, 0)
VERSION = (2, 3, 1)
DEV_N = None


Expand Down
3 changes: 2 additions & 1 deletion adminsortable/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def _get_order_field_value(self):

def save(self, *args, **kwargs):
needs_default = (self._state.adding if VERSION >= (1, 8) else not self.pk)
if not getattr(self, self.order_field_name) and needs_default:
order_value = getattr(self, self.order_field_name)
if order_value is None and needs_default:
try:
current_max = self.__class__.objects.aggregate(
models.Max(self.order_field_name))[self.order_field_name + '__max'] or 0
Expand Down