3838#known issues:
3939#no support for generic relations
4040#no support for one-to-one relations
41- from optparse import make_option
4241from django .core import serializers
4342from django .core .management .base import BaseCommand
4443from django .core .management .base import CommandError
4544from django .core .management .base import LabelCommand
4645from django .db .models .fields .related import ForeignKey
4746from django .db .models .fields .related import ManyToManyField
48- from django .db . models . loading import get_models
47+ from django .apps import apps
4948
5049DEBUG = True
5150
@@ -56,16 +55,17 @@ def model_name(m):
5655class Command (LabelCommand ):
5756 help = 'Output the contents of the database as a fixture of the given format.'
5857 args = 'modelname[pk] or modelname[id1:id2] repeated one or more times'
59- option_list = BaseCommand .option_list + (
60- make_option ('--skip-related' , default = True , action = 'store_false' , dest = 'propagate' ,
61- help = 'Specifies if we shall not add related objects.' ),
62- make_option ('--reverse' , default = [], action = 'append' , dest = 'reverse' ,
63- help = "Reverse relations to follow (e.g. 'Job.task_set')." ),
64- make_option ('--format' , default = 'json' , dest = 'format' ,
65- help = 'Specifies the output serialization format for fixtures.' ),
66- make_option ('--indent' , default = None , dest = 'indent' , type = 'int' ,
67- help = 'Specifies the indent level to use when pretty-printing output' ),
68- )
58+
59+ def add_arguments (self , parser ):
60+ parser .add_argument ('--skip-related' , default = True , action = 'store_false' , dest = 'propagate' ,
61+ help = 'Specifies if we shall not add related objects.' )
62+ parser .add_argument ('--reverse' , default = [], action = 'append' , dest = 'reverse' ,
63+ help = "Reverse relations to follow (e.g. 'Job.task_set')." )
64+ parser .add_argument ('--format' , default = 'json' , dest = 'format' ,
65+ help = 'Specifies the output serialization format for fixtures.' )
66+ parser .add_argument ('--indent' , default = None , dest = 'indent' , type = int ,
67+ help = 'Specifies the indent level to use when pretty-printing output' )
68+
6969 def handle_reverse (self , ** options ):
7070 follow_reverse = options .get ('reverse' , [])
7171 to_reverse = {}
@@ -157,7 +157,7 @@ def handle_models(self, models, **options):
157157 raise CommandError ("Unable to serialize database: %s" % e )
158158
159159 def get_models (self ):
160- return [(m , model_name (m )) for m in get_models ()]
160+ return [(m , model_name (m )) for m in apps . get_models ()]
161161
162162 def get_model_from_name (self , search ):
163163 """Given a name of a model, return the model object associated with it
0 commit comments