Hi there.
I have an Oracle database that I access from Django with a user with
limited privileges that can access some special views the DBA has set up
for me. I wanted to use inspectdb to automatically generate the models for
those views, but it didn't work.
The problem is that the SQL statement that Django uses to fetch the tables
and views [1] for the current user does not properly return the views I
need because the user does not own them, and USER_VIEWS only returns those
VIEWS owned by the user. Not owning a table or a view should not be an
obstacle for automatically generating a model, so my proposal is to extend
the inspectdb to allow selecting what tables and views should be considered
for inspection. This would enable the inspection of tables and/or views
that the user does not own, as long as their name is known.
It would be very easy to do, just add an optional positional argument to
the inspectdb commands for the names of the tables/views and, if it's
available, just inspect those tables/views instead of those returned by the
introspection service.
Here's a patch of a possible solution:
--- django/django/core/management/commands/inspectdb.py 2015-10-31
20:50:57.401113597 +0100
+++
/home/jose/.virtualenvs/ori2/lib/python3.4/site-packages/django/core/management/commands/inspectdb.py
2015-10-31
20:52:26.241112474 +0100
@@ -19,6 +19,8 @@
parser.add_argument('--database', action='store', dest='database',
default=DEFAULT_DB_ALIAS, help='Nominates a database to '
'introspect. Defaults to using the "default" database.')
+ parser.add_argument('table', action='store', nargs='*', type=str,
+ help='Selects what tables or views should be
introspected')
def handle(self, **options):
try:
@@ -50,7 +51,12 @@
yield ''
yield 'from %s import models' % self.db_module
known_models = []
- for table_name in connection.introspection.table_names(cursor):
+ if options['table']:
+ tables_to_introspect = options['table']
+ else:
+ tables_to_introspect =
connection.introspection.table_names(cursor)
+
+ for table_name in tables_to_introspect:
if table_name_filter is not None and
callable(table_name_filter):
if not table_name_filter(table_name):
continue
Regards
P.S.: sorry if I messed up any rule of the contribution guidelines, I'm not
used to contributing to large open source projects.
[1]
https://github.com/django/django/blob/master/django/db/backends/oracle/introspection.py#L54
--
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/e05210bc-919e-4d9b-94a6-a86f51ff2132%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.