|
29
|
1 |
from optparse import make_option |
|
|
2 |
|
|
0
|
3 |
from django.core.management.base import AppCommand |
|
29
|
4 |
from django.db import connections, models, DEFAULT_DB_ALIAS |
|
0
|
5 |
|
|
|
6 |
class Command(AppCommand): |
|
|
7 |
help = 'Prints the SQL statements for resetting sequences for the given app name(s).' |
|
29
|
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 |
|
|
0
|
16 |
output_transaction = True |
|
|
17 |
|
|
|
18 |
def handle_app(self, app, **options): |
|
29
|
19 |
connection = connections[options.get('database', DEFAULT_DB_ALIAS)] |
|
|
20 |
return u'\n'.join(connection.ops.sequence_reset_sql(self.style, models.get_models(app, include_auto_created=True))).encode('utf-8') |