장고의 단짝 친구, django extensions
- 공유 링크 만들기
- X
- 이메일
- 기타 앱
장고의 단짝 친구, django extensions
매번 Django 앱을 시작하면서 항상 requirements.txt 에 포함시키는 앱이 있습니다.
django-extensions==2.2.6
아래와 같이 많은 확장 명령어를 확인할 수 있는데요.
$ python manage.py [django_extensions] admin_generator clean_pyc clear_cache compile_pyc create_command create_jobs create_template_tags delete_squashed_migrations describe_form drop_test_database dumpscript export_emails find_template generate_password generate_secret_key graph_models mail_debug merge_model_instances notes passwd pipchecker print_settings print_user_for_session reset_db reset_schema runjob runjobs runprofileserver runscript runserver_plus set_default_site set_fake_emails set_fake_passwords shell_plus show_template_tags show_templatetags show_urls sqlcreate sqldiff sqldsn sync_s3 syncdata unreferenced_files update_permissions validate_templates
그 중에 제가 자주 사용하는 명령어를 정리해봅니다.
shell_plus
Django shell with autoloading of the apps database models and subclasses of user-defined classes.
장고에서 제공하는 shell 의 향상된 버젼입니다. custom models 에서 추가적인 import 없이 사용할 수 있고, tab 키를 이용한 자동 완성 기능도 훌륭합니다.
$ python manage.py shell_plus --ipython # Shell Plus Model Imports from actstream.models import Action, Follow from admin_interface.models import Theme from allauth.account.models import EmailAddress, EmailConfirmation # Shell Plus Django Imports from django.core.cache import cache from django.conf import settings from django.contrib.auth import get_user_model from django.db import transaction from django.db.models import Avg, Case, Count, F, Max, Min, Prefetch, Q, Sum, When, Exists, OuterRef, Subquery from django.utils import timezone from django.urls import reverse Python 3.7.5 (default, Feb 26 2020, 16:28:00) Type 'copyright', 'credits' or 'license' for more information IPython 7.12.0 -- An enhanced Interactive Python. Type '?' for help. In [1]:
create_command
Creates a command extension directory structure within the specified application. This makes it easy to get started with adding a command extension to your application.
커스텀 명령어 작업을 쉽게 시작하기 위한 템플릿을 제공합니다.
$ python manage.py create_command your_app $ cat your_app/management/commands/sample.py from django.core.management.base import BaseCommand class Command(BaseCommand): help = "My shiny new management command." def add_arguments(self, parser): parser.add_argument('sample', nargs='+') def handle(self, *args, **options): raise NotImplementedError()
graph_models
Creates a GraphViz dot file. You need to send this output to a file yourself. Great for graphing your models. Pass multiple application names to combine all the models into a single dot file.
진행중이던 django 프로젝트에 참여하게 되었을 때, 그 프로젝트를 가장 빨리 이해하는 방법은 models.py 를 파악하는 것입니다. 대부분의 로직들이 models에서 관리되기 때문입니다. 코드를 단순히 읽는 것보다도 graph로 각 모델간의 관계를 그림으로 표현해 준다면 더욱 쉽게 이해를 할 수 있을텐데요. 이 기능을 위해서는 필수라고 생각합니다.
$ python manage.py graph_models your_app your_model -o /tmp/models.png
https://django-extensions.readthedocs.io/en/latest/
from http://pointer81.tistory.com/79 by ccl(A) rewrite - 2020-03-18 09:54:14
- 공유 링크 만들기
- X
- 이메일
- 기타 앱
댓글
댓글 쓰기