From ce88d3217700d4b9f58fac0b8a26b4c69458d023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Poulain?= Date: Mon, 3 Aug 2020 16:58:28 +0200 Subject: [PATCH] =?UTF-8?q?ref(inspectdb):=20d=C3=A9clare=20=C3=A0=20part?= =?UTF-8?q?=20des=20extras=5Fparam=20g=C3=A9n=C3=A9riques?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/management/commands/inspectdb.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drupal2spip_lal/base/management/commands/inspectdb.py b/drupal2spip_lal/base/management/commands/inspectdb.py index d3d2898..35cfc55 100644 --- a/drupal2spip_lal/base/management/commands/inspectdb.py +++ b/drupal2spip_lal/base/management/commands/inspectdb.py @@ -40,9 +40,9 @@ DB_RELATIONS = { 'uid': ('uid', 'users', 'user'), # nb: vid est en redondance avec node_revisions.nid # ceci étant la db est cohérente de ce point de vue - 'vid': ('vid', 'node_revisions', 'published_revision', '+'), + 'vid': ('vid', 'node_revisions', 'published_revision'), 'language': ('language', 'languages'), - 'tnid': ('nid', 'node', 'translation source', '+'), + 'tnid': ('nid', 'node', 'translation source'), }, 'node_revisions': { 'nid': ('nid', 'node', 'node'), @@ -91,6 +91,18 @@ DB_RELATIONS = { } } +# On précise ici des paramètres de la DB. + +DB_PARAMS = { + 'drupal': { + 'node': { + 'vid': {'related_name':'+'}, + 'tnid': {'related_name':'+'}, + }, + }, + 'spip': { + }, +} class Command(BaseCommand): help = "Introspects the database tables in the given database and outputs a Django model module." @@ -219,8 +231,6 @@ class Command(BaseCommand): rel_type = 'OneToOneField' else: rel_type = 'ForeignKey' - if len(relations[column_name]) > 3: - extra_params['related_name'] = relations[column_name][3] rel_to = ( "self" if relations[column_name][1] == table_name else table2model(relations[column_name][1]) @@ -238,6 +248,10 @@ class Command(BaseCommand): field_type += '(' + # Add extra params from DB_PARAMS + if unprefixed_table_name in DB_PARAMS[options['database']]: + extra_params.update(DB_PARAMS[options['database']][unprefixed_table_name].get(column_name, {})) + # Don't output 'id = meta.AutoField(primary_key=True)', because # that's assumed if it doesn't exist. if att_name == 'id' and extra_params == {'primary_key': True}: