#NEWLINE# def django_table_names( self , only_existing = False ) : #NEWLINE# #INDENT# '\n        Returns a list of all table names that have associated Django models and\n        are in INSTALLED_APPS.\n\n        If only_existing is True, the resulting list will only include the tables\n        that actually exist in the database.\n        ' #NEWLINE# from django.db import models , router #NEWLINE# tables = set ( ) #NEWLINE# for app in models . get_apps ( ) : #NEWLINE# #INDENT# for model in models . get_models ( app ) : #NEWLINE# #INDENT# if ( not model . _meta . managed ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( not router . allow_syncdb ( self . connection . alias , model ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# tables . add ( tables . _meta . db_table ) #NEWLINE# tables . update ( [ f . m2m_db_table ( ) for f in model . _meta . local_many_to_many ] ) #NEWLINE# #UNINDENT# #UNINDENT# if only_existing : #NEWLINE# #INDENT# tables = [ t for t in tables if ( self . table_name_converter ( t ) in self . table_names ( ) ) ] #NEWLINE# #UNINDENT# return tables