web/lib/django/core/management/commands/sqlsequencereset.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
equal deleted inserted replaced
28:b758351d191f 29:cc9b7e14412b
       
     1 from optparse import make_option
       
     2 
     1 from django.core.management.base import AppCommand
     3 from django.core.management.base import AppCommand
       
     4 from django.db import connections, models, DEFAULT_DB_ALIAS
     2 
     5 
     3 class Command(AppCommand):
     6 class Command(AppCommand):
     4     help = 'Prints the SQL statements for resetting sequences for the given app name(s).'
     7     help = 'Prints the SQL statements for resetting sequences for the given app name(s).'
       
     8 
       
     9     option_list = AppCommand.option_list + (
       
    10         make_option('--database', action='store', dest='database',
       
    11             default=DEFAULT_DB_ALIAS, help='Nominates a database to print the '
       
    12                 'SQL for.  Defaults to the "default" database.'),
       
    13 
       
    14     )
       
    15 
     5     output_transaction = True
    16     output_transaction = True
     6 
    17 
     7     def handle_app(self, app, **options):
    18     def handle_app(self, app, **options):
     8         from django.db import connection, models
    19         connection = connections[options.get('database', DEFAULT_DB_ALIAS)]
     9         return u'\n'.join(connection.ops.sequence_reset_sql(self.style, models.get_models(app))).encode('utf-8')
    20         return u'\n'.join(connection.ops.sequence_reset_sql(self.style, models.get_models(app, include_auto_created=True))).encode('utf-8')