Opened 3 hours ago

#36113 new Cleanup/optimization

Enhancement Proposal: Support for Nested App Creation with `startapp` Command in Django

Reported by: Jerin Kachirackal Owned by:
Component: Core (Management commands) Version:
Severity: Normal Keywords: core, command, startapp, optimization
Cc: Jerin Kachirackal Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Summary:

Django's startapp command currently creates a new app at the root level of the project. Developers often adopt different project structures, and many prefer organizing apps within subdirectories for better modularity and clarity. A common structure might look like this:

|-- ./
|-- ./apps/<app name>
|-- ./apps/<app name>/apis/
|-- ./apps/dashboard/<app name>
|-- ./manage.py

To achieve this structure, developers currently need to:

  1. Run python manage.py startapp <app-name>.
  2. Manually move the generated app into the desired directory.
  3. Update the apps.py configuration to reflect the new structure.

This process is tedious, error-prone, and does not contribute to creating a "structured" project, particularly for first-time users.

Proposed Enhancement:

Enhance the startapp command to support nested app creation directly by specifying the full path.
Proposed Comand:

For Linux / Mac

python manage.py startapp apps/dashboard/user

(or for Windows with a \ instead of / as we expect)

Proposed Changes:
This command should:

  • Automatically create the nested directory structure apps/dashboard/user. * '[Clarification1]
  • Populate apps/dashboard/user/apps.py with the correct configuration for apps.dashboard.user. using the classname AppsDashboardUserConfig and name as apps.dashboard.user
    from django.apps import AppConfig
    
    
    class AppsDashboardUserConfig(AppConfig):
        default_auto_field = 'django.db.models.BigAutoField'
        name = 'apps.dashboard.user'
    
    
  • Provide a log message or output suggesting the exact string to add to INSTALLED_APPS, e.g.,:
    $ user@host: proj % django-admin startapp user apps/dashboard/user
    App added to following directory : `apps.dashboard.user` 
    To integrate this app with your project, please add the following line in your `settings.INSTALLED_APPS`.
    """
    INSTALLED_APPS = [
        ...,
        'apps.dashboard.user.apps.AppsDashboardUserConfig',
        ...,
    ]
    """
    
    $ user@host: proj % 
    

Benefits:

  • Simplifies app creation for projects with nested or modular structures.
  • Reduces manual steps and the risk of configuration errors.
  • Enhances the developer experience, particularly for newcomers to Django.
  • Keeping developer actions DRY and productive with minimum commands.

Compatibility:

The proposed change should maintain backward compatibility, allowing the current behavior (creating apps in the root directory) to remain unchanged when the provided path does not include subdirectories.


Clarifications
[Clarification1]: Django currently requires directories to be created manually. Respecting this, the proposal suggests creating the directory (if the user has permission). For projects requiring structured apps, this enhancement reduces repetitive bugs and increases efficiency.


A Note from Reporter:
I am working with django for last 7 years, introducing the same from startups to saas, - and would like to add such a contribution from my end, if this can be assigned to me. Even else, the feature expects to be a simple and wish to find as a part of django.

Thank You!

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top