django_admin_generator package¶
Submodules¶
Helpers for discovering installed apps and their models.
- django_admin_generator.discovery.get_apps() Iterator[tuple[str, AppConfig]][source]¶
Yield
(name, app_config)for every installed app.Each app is yielded twice: once under its full dotted path and once under its short (last component) name so both can be used as lookups.
- django_admin_generator.discovery.get_local_apps() list[AppConfig][source]¶
Return the apps that live inside the project (not site-packages).
- django_admin_generator.discovery.get_models(app: AppConfig) Iterator[type[Model]][source]¶
Yield every model registered on
app.
Model introspection and admin.py source generation.
- class django_admin_generator.generators.AdminApp(app: AppConfig, model_res: list[Pattern[str]], **options: Any)[source]¶
Bases:
objectRender the admin classes for every (matching) model in an app.
- class django_admin_generator.generators.AdminModel(model: type[Model], raw_id_threshold: int = 100, date_hierarchy_threshold: int = 250, list_filter_threshold: int = 25, search_field_names: tuple[str, ...] = ('name', 'slug'), date_hierarchy_names: tuple[str, ...] = ('joined_at', 'updated_at', 'created_at'), prepopulated_field_names: tuple[str, ...] = ('slug=name',), no_query_db: bool = False, auto_complete: list[str] | None = None, disable_auto_complete: bool = False, **options: Any)[source]¶
Bases:
objectIntrospect a single model and render its
ModelAdminbody.- NON_DISTINCT_FIELDS: ClassVar[tuple[type[AnyField], ...]] = (<class 'django.db.models.fields.TextField'>, <class 'django.db.models.fields.json.JSONField'>, <class 'django.db.models.fields.BinaryField'>, <class 'django.db.models.fields.files.FileField'>)¶
Field types that do not support
DISTINCTon some databases (PostgreSQL, Oracle, SQL Server) and must be kept out of thedistinct()queries used to populatelist_filter.
Default thresholds and field-name heuristics for admin generation.
- django_admin_generator.constants.DATE_HIERARCHY_NAMES: Final[tuple[str, ...]] = ('joined_at', 'updated_at', 'created_at')¶
Field names that are good candidates for
date_hierarchy.
- django_admin_generator.constants.LIST_FILTER: Final[tuple[type[models.Field[Any, Any]], ...]] = (<class 'django.db.models.fields.DateField'>, <class 'django.db.models.fields.DateTimeField'>, <class 'django.db.models.fields.related.ForeignKey'>, <class 'django.db.models.fields.BooleanField'>)¶
Field types that are good candidates for
list_filter.
- django_admin_generator.constants.PREPOPULATED_FIELD_NAMES: Final[tuple[str, ...]] = ('slug=name',)¶
field=other_fieldspecs that should end up inprepopulated_fields.
- django_admin_generator.constants.SEARCH_FIELD_NAMES: Final[tuple[str, ...]] = ('name', 'slug')¶
Field names that should end up in
search_fields.
String templates used to render the generated admin.py source.