Dynamic Model
get_dynamic_model
- slick_reporting.dynamic_model.get_dynamic_model(table_name, database='default', schema=None)[source]
Introspect a database table and return a Django model class for it.
The returned model has
managed = Falseand is fully compatible with the Django ORM. Results are cached so repeated calls return the same class.- Parameters:
table_name (str) – The database table name to introspect.
database (str) – The database alias from
DATABASESsetting.schema (str or None) – Optional schema name (PostgreSQL). The schema must be in the connection’s
search_path. When provided,db_tableis set to"schema"."table_name".
- Returns:
A Django model class mapped to the table.
- Return type:
type (subclass of
django.db.models.Model)- Raises:
ValueError – If the table does not exist.
table_name attribute
Both ReportGenerator and ReportView accept a table_name parameter.
When set (and report_model is not), get_dynamic_model is called automatically.
class MyReport(ReportView):
table_name = "legacy_sales"
date_field = "sale_date"
group_by = "region"
columns = [...]
# Or via ReportGenerator init
report = ReportGenerator(table_name="legacy_sales", ...)
See Dynamic Models for full usage guide and examples.