Skip to content

Commit 1441aea

Browse files
committed
Fixes jrief#76
1 parent d6d61f4 commit 1441aea

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

adminsortable2/management/commands/reorder.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
from django.core.management.base import BaseCommand, CommandError
3-
from django.utils.module_loading import import_by_path
4-
from django.core import exceptions
3+
from django.utils.module_loading import import_string
54

65

76
class Command(BaseCommand):
@@ -11,12 +10,14 @@ class Command(BaseCommand):
1110
def handle(self, *args, **options):
1211
for modelname in args:
1312
try:
14-
Model = import_by_path(modelname)
15-
except exceptions.ImproperlyConfigured:
13+
Model = import_string(modelname)
14+
except ImportError:
1615
raise CommandError('Unable to load model "%s"' % modelname)
1716
if not hasattr(Model._meta, 'ordering') or len(Model._meta.ordering) == 0:
1817
raise CommandError('Model "{0}" does not define field "ordering" in its Meta class'.format(modelname))
1918
orderfield = Model._meta.ordering[0]
19+
if orderfield[0] == '-':
20+
orderfield = orderfield[1:]
2021
for order, obj in enumerate(Model.objects.iterator(), start=1):
2122
setattr(obj, orderfield, order)
2223
obj.save()

0 commit comments

Comments
 (0)