ref(inspectdb): déclare à part des extras_param génériques

wip_revisions
François Poulain 2 years ago
parent 892944927a
commit ce88d32177
  1. 22
      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}:

Loading…
Cancel
Save