Skip to main content

A Django management command to create apps in a subdirectory (e.g., apps/) for better project organization

Project description

django-startsubapp

A Django management command that creates Django apps inside a dedicated apps/ folder to keep your project structure clean and organized.

Features

  • ๐Ÿš€ Create Django apps directly inside the apps/ folder
  • ๐Ÿ“ฆ Automatically handles app structure and configuration
  • ๐Ÿ”ง Simple command: python manage.py startsubapp [app_name]
  • ๐Ÿ›ก๏ธ Input validation to prevent errors
  • โœจ Enhanced user feedback with status messages

Installation

Via PyPI

pip install django-startsubapp

Development Installation

git clone https://github.com/Saman-naruee/django-startsubapp.git
cd django-startsubapp
pip install -e .

Quick Start

1. Add to Django Project

Add startsubapp to your Django project's INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    # ... other apps
    'startsubapp',
]

2. Create a New Sub-App

Run the management command:

python manage.py startsubapp myapp

This will create:

myproject/
โ”œโ”€โ”€ apps/
โ”‚   โ””โ”€โ”€ myapp/
โ”‚       โ”œโ”€โ”€ migrations/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ admin.py
โ”‚       โ”œโ”€โ”€ apps.py
โ”‚       โ”œโ”€โ”€ models.py
โ”‚       โ”œโ”€โ”€ tests.py
โ”‚       โ”œโ”€โ”€ views.py
โ”‚       โ””โ”€โ”€ ...
โ”œโ”€โ”€ manage.py
โ””โ”€โ”€ ...

3. Update Your Settings

Add the new app to INSTALLED_APPS:

INSTALLED_APPS = [
    # ... other apps
    'apps.myapp',  # Note: apps.myapp format
]

Usage

Command Syntax

python manage.py startsubapp [app_name]

Example

Create an accounts app:

python manage.py startsubapp accounts

This creates apps/accounts/ with all necessary Django app files.

How It Works

  1. Creates the apps/ folder if it doesn't exist
  2. Uses Django's built-in startapp command to create the app structure
  3. Moves the app from the project root into the apps/ folder
  4. Ensures proper __init__.py exists in the app directory
  5. Automatically configures the app's apps.py with the correct path

Error Handling

The command includes validation for:

  • Invalid app names: Prevents dots (.) in app names
  • Existing apps: Checks for conflicts before creation
  • File system errors: Handles file operations safely

Example error message:

$ python manage.py startsubapp my.app
Error: Dots not allowed in app_name. Use simple name like 'accounts'

Project Structure

The package follows modern Python packaging standards:

django-startsubapp/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ startsubapp/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ apps.py
โ”‚       โ””โ”€โ”€ management/
โ”‚           โ””โ”€โ”€ commands/
โ”‚               โ””โ”€โ”€ startsubapp.py
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ test_basic.py
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ setup.cfg
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ LICENSE
โ””โ”€โ”€ .gitignore

Requirements

  • Python 3.8+
  • Django 3.0+

Testing

Run tests with:

python -m pytest tests/

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Saman Naruee

Support

If you encounter any issues, please open an issue on GitHub.

Changelog

v1.0.0 (Initial Release)

  • Initial release of django-startsubapp
  • Basic functionality for creating sub-apps in apps/ folder
  • Full validation and error handling
  • PyPI publication

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_startsubapp-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_startsubapp-1.0.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file django_startsubapp-1.0.0.tar.gz.

File metadata

  • Download URL: django_startsubapp-1.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for django_startsubapp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a5cfd1a903ce900cee66bd9b7346b68da100d4e0c8ec6a411b25d54054877cd3
MD5 1b9d2db18321a653479339830322813b
BLAKE2b-256 c82620c98abbb8e8e2924b794865b7f4530ef6aef6f698ab34ccfd12473adcde

See more details on using hashes here.

File details

Details for the file django_startsubapp-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_startsubapp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a422637965db93cc27e98c5ec8605fa0f8e1e2cb598595eb915a60031c4d374f
MD5 8e510e1dcee94eba66110c427f12ce4f
BLAKE2b-256 63a6e545466bb4e6c81cd09c66e35c35300768dd361929b21505a5d1303b1624

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page