Django 1.8 inspectdb command doesn't see PostgreSQL views as per documentation
As of Django 1.10, you can simply name an individual view as a parameter to your inspectdb
command:
$ python well/manage.py inspectdb hospitalizations_over_30_days
The default inspectdb
will only output models.py for tables, but models for views can be generated individually by naming them.
If you want inspectdb
to generate models for all tables and views, use the inspectdb --include-views
option, which I contributed to Django 2.1 as a result of this question!
To generate models for both tables and views in Django 2.0 and below, you have to edit the Django source code. In Django 2.0, change line 57 in django/core/management/commands/inspectdb.py
to:
tables_to_introspect = options['table'] or connection.introspection.table_names(cursor=cursor, include_views=True)
Beware that the generated models won't have fields with primary_key=True
set, you will need to add primary keys manually.