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: object

Render 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: object

Introspect a single model and render its ModelAdmin body.

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 DISTINCT on some databases (PostgreSQL, Oracle, SQL Server) and must be kept out of the distinct() queries used to populate list_filter.

PRINTABLE_PROPERTIES: ClassVar[tuple[str, ...]] = ('list_display', 'list_filter', 'raw_id_fields', 'autocomplete_fields', 'search_fields', 'prepopulated_fields', 'date_hierarchy')
property name: str

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_field specs that should end up in prepopulated_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.

Subpackages

Module contents