{"id":21983079,"url":"https://github.com/arsho/django-custom-command","last_synced_at":"2026-04-28T17:33:43.568Z","repository":{"id":46849689,"uuid":"251383105","full_name":"arsho/django-custom-command","owner":"arsho","description":null,"archived":false,"fork":false,"pushed_at":"2021-09-22T18:49:17.000Z","size":203,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T04:46:15.807Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arsho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-30T17:46:08.000Z","updated_at":"2020-04-01T05:16:24.000Z","dependencies_parsed_at":"2022-08-29T00:41:06.663Z","dependency_job_id":null,"html_url":"https://github.com/arsho/django-custom-command","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arsho%2Fdjango-custom-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arsho%2Fdjango-custom-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arsho%2Fdjango-custom-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arsho%2Fdjango-custom-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arsho","download_url":"https://codeload.github.com/arsho/django-custom-command/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245043736,"owners_count":20551833,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-29T17:34:22.933Z","updated_at":"2026-04-28T17:33:38.548Z","avatar_url":"https://github.com/arsho.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Django Custom Command Example with Django Docs Polls Application\nThis is the code repository of the following tutorial: [https://arshovon.com/blog/django-custom-command/](https://arshovon.com/blog/django-custom-command/)\n\n\n### Directory Structure\n\n```\n.\n├── mysite\n│   ├── manage.py\n│   ├── mysite\n│   │   ├── asgi.py\n│   │   ├── __init__.py\n│   │   ├── settings.py\n│   │   ├── urls.py\n│   │   └── wsgi.py\n│   └── polls\n│       ├── admin.py\n│       ├── apps.py\n│       ├── __init__.py\n│       ├── management\n│       │   └── commands\n│       │       ├── command_utils.py\n│       │       ├── insert_dummy_questions.py\n│       │       └── questions.csv\n│       ├── migrations\n│       │   ├── 0001_initial.py\n│       │   └── __init__.py\n│       ├── models.py\n│       ├── templates\n│       │   └── polls\n│       │       ├── detail.html\n│       │       ├── index.html\n│       │       └── results.html\n│       ├── tests.py\n│       ├── urls.py\n│       └── views.py\n└── requirements.txt\n```\n\n### Installing Requirements\n- Python version: 3.6+\n- Create virtual environment:\n    ```\n    python3 -m venv venv\n    ```\n- Activate virtual environment:\n    ```\n    source venv/bin/activate\n    ```\n- Install required packages:\n    ```\n    pip install -r requirements.txt\n    ```\n### Database Migration\n- Create migration:\n    ```\n    python manage.py makemigrations\n    ```\n- Migrate migrations:\n    ```\n    python manage.py migrate\n    ```\n- Create super user:\n    ```\n    python manage.py createsuperuser\n    ```\n\n### Run the project\n- Run the project from the root directory of Django project:\n    ```\n    python manage.py runserver\n    ```\n\n### Run Django Custom Command\n- Run Django custom command `help` context:\n    ```\n    python manage.py insert_dummy_questions --help\n    ```\n    \n    ![alt Django Custom Command Help context](/screenshots/django_custom_command_help.png?style=center)\n\n- Run Django custom command:\n\n    ```\n    python manage.py insert_dummy_questions questions.csv\n    ```\n\n    ![alt Django Custom Command](/screenshots/running_custom_django_command.png?style=center)\n\n- After running Django custom command the CSV file data is inserted into database:\n\n![alt Polls page](/screenshots/polls_custom_django_command.png?style=center)  \n\n### Footnote\n\n- I have used Django Docs Example Polls Application to demonstrate Django Custom Command.\n- Utility methods of custom command files are kept in a separate file in `mysite/polls/management/commands/command_utils.py`. Then in custom command file I have imported required methods like: `from .command_utils import get_csv_file`\n\n\n\n### Reference\n- [Writing Django Custom Management Command](https://arshovon.com/blog/django-custom-command/)\n- [Custom commands in Django](https://docs.djangoproject.com/en/2.2/howto/custom-management-commands/)\n- [Writing your first Django app, part 1](https://docs.djangoproject.com/en/3.0/intro/tutorial01/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farsho%2Fdjango-custom-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farsho%2Fdjango-custom-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farsho%2Fdjango-custom-command/lists"}