1. hideki nara
  2. mandb

Commits

hideki nara  committed 24aed55

object id can be specified.

  • Participants
  • Parent commits ff07db9
  • Branches default

Comments (0)

Files changed (1)

File src/mandb/management/commands/db.py

View file
             default='.fixtures',
             help=u'directory to save output files'),
         
+        make_option('--id',
+            action='store',
+            dest='object_id',
+            default='None',
+            help=u'sepcify model object id'),
+       
     )
 
     def sql(self, statement ):
         ''' 指定したモデルのfixtureを作る
         '''
         import os
+        from django.core import serializers
 
         mcs = self.handle_model_list(console=False,*args,**options)
         if len(mcs) < 1 or mcs[0] == None:
         if os.path.isdir(options['directory'] ) == False:
             os.makedirs(options['directory'] )   
 
-        from django.core import serializers
         for mc in mcs :
-            for obj in mc.objects.all():
+
+            objects = mc.objects.filter(id=options['object_id']) \
+                    if options['object_id']  else mc.objects.all()
+
+            for obj in objects:
                 fname= os.path.join(options['directory'],
                         "fixture.%s.%d.json" % (obj._meta.db_table,obj.id) )
                 f= open(fname,"w") 
                         indent=2).encode('utf8') 
                 )   
                 f.close()    
+        
 
     def handle(self, *args, **options):
         '''  handler