fix(inspectdb): va au bout de la logique des pefixes de table
This commit is contained in:
parent
320be647fa
commit
892944927a
@ -4,7 +4,7 @@ import re
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.db import DEFAULT_DB_ALIAS, connections
|
||||
from django.db.models.constants import LOOKUP_SEP
|
||||
|
||||
from django.utils.text import camel_case_to_spaces
|
||||
|
||||
# On reconstruit ici la hiérarchie de la DB que les dev php n'ont pas été
|
||||
# capables de spécifier en sql. On en profite pour donner des noms explicites.
|
||||
@ -160,13 +160,14 @@ class Command(BaseCommand):
|
||||
types.add('v')
|
||||
|
||||
for table_name in (options['table'] or sorted(info.name for info in table_info if info.type in types)):
|
||||
unprefixed_table_name = camel_case_to_snake(table2model(table_name))
|
||||
if table_name_filter is not None and callable(table_name_filter):
|
||||
if not table_name_filter(table_name):
|
||||
continue
|
||||
try:
|
||||
try:
|
||||
relations = connection.introspection.get_relations(cursor, table_name)
|
||||
relations.update(DB_RELATIONS[options['database']].get(table_name, {}))
|
||||
relations.update(DB_RELATIONS[options['database']].get(unprefixed_table_name, {}))
|
||||
except NotImplementedError:
|
||||
relations = {}
|
||||
try:
|
||||
@ -404,3 +405,10 @@ class Command(BaseCommand):
|
||||
tup = '(' + ', '.join(unique_together) + ',)'
|
||||
meta += [" unique_together = %s" % tup]
|
||||
return meta
|
||||
|
||||
|
||||
def camel_case_to_snake(value):
|
||||
"""
|
||||
Split CamelCase and convert to snakecase.
|
||||
"""
|
||||
return camel_case_to_spaces(value).replace(' ', '_')
|
||||
|
Loading…
Reference in New Issue
Block a user