File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed
adminsortable2/management/commands Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
2
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
5
4
6
5
7
6
class Command (BaseCommand ):
@@ -11,12 +10,14 @@ class Command(BaseCommand):
11
10
def handle (self , * args , ** options ):
12
11
for modelname in args :
13
12
try :
14
- Model = import_by_path (modelname )
15
- except exceptions . ImproperlyConfigured :
13
+ Model = import_string (modelname )
14
+ except ImportError :
16
15
raise CommandError ('Unable to load model "%s"' % modelname )
17
16
if not hasattr (Model ._meta , 'ordering' ) or len (Model ._meta .ordering ) == 0 :
18
17
raise CommandError ('Model "{0}" does not define field "ordering" in its Meta class' .format (modelname ))
19
18
orderfield = Model ._meta .ordering [0 ]
19
+ if orderfield [0 ] == '-' :
20
+ orderfield = orderfield [1 :]
20
21
for order , obj in enumerate (Model .objects .iterator (), start = 1 ):
21
22
setattr (obj , orderfield , order )
22
23
obj .save ()
You can’t perform that action at this time.
0 commit comments