Skip to main content

Django subcommands in subdirectories

Project description

django-subcommandir

GitHub Actions PyPI PyPI - Python Version framework - Django PyPI - Django Version PyPI - License

Django subcommands in subdirectories

Installation

$ pip install django-subcommandir

Example of usage

my_app
├── ...
├── management
│   ├── commands
│      ├── __init__.py
│      ├── load
│         ├── __init__.py
│         ├── month_report.py
│         └── year_report.py
│      ├── my_app_load.py
│   ├── __init__.py
# .../management/commands/my_app_load.py
from subcommandir import BaseCommand

class Command(BaseCommand):
    subcommand_dir = 'load'
# .../management/commands/load/month_report.py
from django.core.management.base import BaseCommand

class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument('--start', ...)
        ...

    def handle(self, *args, **options):
        ...

Command calls:

$ python manage.py my_app_load year_report
$ python manage.py my_app_load month_report --start="2021-01" --end="2021-02"

or

from django.core.management import call_command

def load_year_report():
    call_command('my_app_load', 'year_report')
    
def load_month_report():
    call_command('my_app_load', 'month_report', start=...)

License

MIT

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-subcommandir-0.2.0.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

django_subcommandir-0.2.0-py3-none-any.whl (6.6 kB view hashes)

Uploaded Python 3

Supported by

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