TIL #1. 2020-02-07

정은경·2020년 1월 7일
0

🧩 Me Today 

목록 보기
10/48

오늘의 궁금증

Q1. 어짜피 DB에 저장하는데 자료구조 왜필요해요?

Q2. 데코레이터는 Unit Test 어떻게해요?

Q3. User의 비밀번호 변경일 관리는 어떻게 하나요?

장고 DB 실습

  • 장고 모델 형태

  • prefetch_related 실습

>>> temp = User.objects.prefetch_related('product_set').get(id=1)
>>> temp.product_set
<django.db.models.fields.related_descriptors.create_forward_many_to_many_manager.<locals>.ManyRelatedManager object at 0x10fdf3410>
>>> temp.product_set.all()
<QuerySet [<Product: Product object (1)>, <Product: Product object (2)>, <Product: Product object (3)>]>
>>> temp.product_set.all().values()
<QuerySet [{'id': 1, 'name': 'p1', 'image': 'img!p1', 'brand_id_id': None}, {'id': 2, 'name': 'p2', 'image': 'img!p2', 'brand_id_id': None}, {'id': 3, 'name': 'p3', 'image': 'img!p3', 'brand_id_id': None}]>
>>>
  • ManyToMany 필드를 지정한 클래스에서
>>> temp = Product.objects.get(id=1)
>>> temp.product_like
<django.db.models.fields.related_descriptors.create_forward_many_to_many_manager.<locals>.ManyRelatedManager object at 0x10fe0a050>
>>> temp.product_like.all()
<QuerySet [<User: User object (1)>]>
>>> temp.product_like.all().values()
<QuerySet [{'id': 1, 'name': 'name1', 'age': 11}]>
>>>

장고DB 실습

-- 끼워넣기 --                                                         4,1          모두drwxr-xr-x   3 marie  staff    96  1  7 19:51 .
drwxr-xr-x+ 72 marie  staff  2304  1  7 19:51 ..
drwxr-xr-x   4 marie  staff   128  1  7 19:51 dmp_jek
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107 »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107 »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107 » cd dmp_jek
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » ls -al
total 8
drwxr-xr-x  4 marie  staff  128  1  7 19:51 .
drwxr-xr-x  3 marie  staff   96  1  7 19:51 ..
drwxr-xr-x  7 marie  staff  224  1  7 19:51 dmp_jek
-rwxr-xr-x  1 marie  staff  627  1  7 19:51 manage.py
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
-- 끼워넣기 --                                                       4,1         모두
from django.db import models
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » django-admin startapp test
CommandError: 'test' conflicts with the name of an existing Python module and cannot be used as an app name. Please try another name.
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » django-admin startapp sample       1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
    'django.middleware.common.CommonMiddleware',
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi ./sample/models.py
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
DATABASES = {
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » tree
.
├── dmp_jek
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-37.pyc
│   │   └── settings.cpython-37.pyc
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
└── sample
    ├── __init__.py
    ├── admin.py
    ├── apps.py
    ├── migrations
    │   └── __init__.py
    ├── models.py
    ├── tests.py
    └── views.py

(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi ./dmp_jek/settings.py
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » ls -al
total 8
drwxr-xr-x  5 marie  staff  160  1  7 19:53 .
drwxr-xr-x  3 marie  staff   96  1  7 19:51 ..
drwxr-xr-x  8 marie  staff  256  1  7 20:12 dmp_jek
-rwxr-xr-x  1 marie  staff  627  1  7 19:51 manage.py
drwxr-xr-x  9 marie  staff  288  1  7 20:11 sample
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » pwd
/Users/marie/django_model_practice_20200107/dmp_jek
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi my_settings.py
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
DATABASES = {
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py makemigrati
Traceback (most recent call last):
  File "manage.py", line 21, in <module>

    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/__init__.py", line 345, in execute
    settings.INSTALLED_APPS
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/conf/__init__.py", line 76, in __getattr__
    self._setup(name)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/conf/__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/conf/__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/marie/django_model_practice_20200107/dmp_jek/dmp_jek/settings.py", line 76, in <module>
    DATABASES = my_settings.DATABASES
NameError: name 'my_settings' is not defined
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                   1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                   1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                   1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi my_settings.py 1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi ./dmp_jek/settings.py
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py makemigrati
Unknown command: 'makemigrati'. Did you mean makemigrations?
Type 'manage.py help' for usage.
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                   1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                   1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py makemigrations
Traceback (most recent call last):
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
    self.connect()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection
    return Database.connect(**conn_params)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/MySQLdb/__init__.py", line 84, in Connect
    return Connection(*args, **kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/MySQLdb/connections.py", line 179, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
MySQLdb._exceptions.OperationalError: (1049, "Unknown database 'dmp`_db'")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/base.py", line 366, in execute
    self.check()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/base.py", line 395, in check
    include_deployment_checks=include_deployment_checks,
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/base.py", line 382, in _run_checks
    return checks.run_checks(**kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/checks/model_checks.py", line 34, in check_all_models
    errors.extend(model.check(**kwargs))
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/base.py", line 1274, in check
    *cls._check_constraints(),
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/base.py", line 1840, in _check_constraints
    connection.features.supports_table_check_constraints or
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/mysql/features.py", line 93, in supports_column_check_constraints
    if self.connection.mysql_is_mariadb:
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 363, in mysql_is_mariadb
    return 'mariadb' in self.mysql_server_info.lower()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 350, in mysql_server_info
    with self.temporary_connection() as cursor:
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/base/base.py", line 604, in temporary_connection
    with self.cursor() as cursor:
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/base/base.pyDATABASES = {
", line 260, in cursor
    return self._cursor()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/base/base.py", line 236, in _cursor
    self.ensure_connection()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
    self.connect()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/base/base.py", line 220, in ensure_connection
    self.connect()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 233, in get_new_connection
    return Database.connect(**conn_params)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/MySQLdb/__init__.py", line 84, in Connect
    return Connection(*args, **kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/MySQLdb/connections.py", line 179, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (1049, "Unknown database 'dmp`_db'")
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                   1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi my_settings.py 1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py makemigrations
No changes detected
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
import os
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying sessions.0001_initial... OK

(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » tree
.
├── __pycache__
│   └── my_settings.cpython-37.pyc
├── dmp_jek
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-37.pyc
│   │   ├── settings.cpython-37.pyc
│   │   └── urls.cpython-37.pyc
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
├── my_settings.py
└── sample
    ├── __init__.py
    ├── admin.py
    ├── apps.py
    ├── migrations
    │   └── __init__.py
    ├── models.py
    ├── tests.py
    └── views.py

5 directories, 18 files
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi my_settings.py
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi ./dmp_jek/settings.py
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi ./dmp_jek/settings.py
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » pwd
/Users/marie/django_model_practice_20200107/dmp_jek
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » ls
__pycache__    dmp_jek        manage.py      my_settings.py sample
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
from django.db import models
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py makemigrations
Traceback (most recent call last):
from django.db import models
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/marie/django_model_practice_20200107/dmp_jek/sample/models.py", line 4, in <module>
    class Product(models.Model):
  File "/Users/marie/django_model_practice_20200107/dmp_jek/sample/models.py", line 6, in Product
    image = models.CharField(max_legnth = 300)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 980, in __init__
    super().__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'max_legnth'
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                                           1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                                           1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi ./sample/models.py                     1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi ./sample/models.py
from django.db import models
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py makemigrations
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
from django.db import models
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/marie/django_model_practice_20200107/dmp_jek/sample/models.py", line 20, in <module>
    class User(models.Model):
  File "/Users/marie/django_model_practice_20200107/dmp_jek/sample/models.py", line 21, in User
    name = models.CharField(max_legnth = 300)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 980, in __init__
    super().__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'max_legnth'
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi ./sample/models.py                     1(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py makemigrations
Migrations for 'sample':
  sample/migrations/0001_initial.py
    - Create model Brand
    - Create model Product
    - Create model User
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sample, sessions
Running migrations:
  Applying sample.0001_initial... OK
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » vi ./sample/models.py
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py makemigrations
Migrations for 'sample':
  sample/migrations/0002_product_brand_id.py
    - Add field brand_id to product
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sample, sessions
Running migrations:
  Applying sample.0002_product_brand_id... OK
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python shell
python: can't open file 'shell': [Errno 2] No such file or directory
(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                                           2(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                                           2(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                                           2(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek »                                           2(wehome_conda) marie@MarieJungui-MacBookPro:~/django_model_practice_20200107/dmp_jek » python manage.py shell                    2 ↵
Python 3.7.5 (default, Oct 25 2019, 10:52:18)
[Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
>>>
>>> from sample.models import *
>>>
>>>
>>> Users.objects.all()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'Users' is not defined
>>>
>>>
>>>
>>>
>>> User(name="jek0").save()
>>>
>>>
>>> Users.objects.all()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'Users' is not defined
>>> User.objects.all()
<QuerySet [<User: User object (1)>]>
>>>
>>>
>>> User.objects.all().values()
<QuerySet [{'id': 1, 'name': 'jek0', 'age': 10}]>
>>>
>>>
>>> User.objects
<django.db.models.manager.Manager object at 0x104a43250>
>>> User
<class 'sample.models.User'>
>>>
>>> User.objects
<django.db.models.manager.Manager object at 0x104a43250>
>>>
>>> User.objects.values()
<QuerySet [{'id': 1, 'name': 'jek0', 'age': 10}]>
>>>
>>>
>>>
>>> User(name="jek1", age="11").save()
>>>
>>>
>>> User
<class 'sample.models.User'>
>>>
>>>
>>> User.objects
<django.db.models.manager.Manager object at 0x104a43250>
>>>
>>> User.object
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: type object 'User' has no attribute 'object'
>>>
>>> User.objects
<django.db.models.manager.Manager object at 0x104a43250>
>>> User.objects.all
<bound method BaseManager.all of <django.db.models.manager.Manager object at 0x104a43250>>
>>> User.objects.all()
<QuerySet [<User: User object (1)>, <User: User object (2)>]>
>>>
>>> User.objects.values()
<QuerySet [{'id': 1, 'name': 'jek0', 'age': 10}, {'id': 2, 'name': 'jek1', 'age': 11}]>
>>>
>>>
>>> User.objects.all().values()
<QuerySet [{'id': 1, 'name': 'jek0', 'age': 10}, {'id': 2, 'name': 'jek1', 'age': 11}]>
>>>
>>>
>>> User.get(id=1)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: type object 'User' has no attribute 'get'
>>> User.get(id='1')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: type object 'User' has no attribute 'get'
>>>
>>> User.objects.get(id=1)
<User: User object (1)>
>>> User.objects.get(id=1).values()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'User' object has no attribute 'values'
>>> type(User)
<class 'django.db.models.base.ModelBase'>
>>>
>>> type(User.objects)
<class 'django.db.models.manager.Manager'>
>>>
>>> type(User.objects.all())
<class 'django.db.models.query.QuerySet'>
>>>
>>> type(User.objects.get(id=1))
<class 'sample.models.User'>
>>>
>>>
>>> isintace(User, User.objects.get(id-1))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'isintace' is not defined
>>> isinstace(User, User.objects.get(id-1))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'isinstace' is not defined
>>> isinstance(User, User.objects.get(id=1))
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: isinstance() arg 2 must be a type or tuple of types
>>>
>>> isinstance(User.objects.get(id=1), User)
True
>>>
>>> isinstance(User.objects.get(id=1), models.Model)
True
>>> isinstance(User.objects.get(id=1), django.db)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'django' is not defined
>>> isinstance(User.objects.get(id=1), django.db.models)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'django' is not defined
>>> isinstance(User.objects.get(id=1), django.db.models.query)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'django' is not defined
>>> isinstance(User.objects.all(), django.db.models.query)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'django' is not defined
>>> isinstance(User.objects.all(), django.db.models)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'django' is not defined
>>>
>>> isinstance(User.objects.all(), User)
False
>>>
>>>
>>>
>>> Product.select_related(User)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: type object 'Product' has no attribute 'select_related'
>>>
>>>
>>> Product.objects.select_related(User)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 1008, in select_related
    obj.query.add_select_related(fields)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/query.py", line 1950, in add_select_related
    for part in field.split(LOOKUP_SEP):
AttributeError: type object 'User' has no attribute 'split'
>>>
>>>
>>> Product.objects.select_related(brand_id)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'brand_id' is not defined
>>> Product.objects.select_related(brand_id_id)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'brand_id_id' is not defined
>>>
>>>
>>>
>>>
>>>
>>> Brand(name="brand1", logo="logoB1").save()
>>>
>>>
>>> Brand.objects.get(name="brand1")
<Brand: Brand object (1)>
>>> Brand.objects.get(name="brand1").values()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'Brand' object has no attribute 'values'
>>> Brand.objects.all().values()
<QuerySet [{'id': 1, 'name': 'brand1', 'logo': 'logoB1'}]>
>>>
>>>
>>>
>>>
>>> Brand(name="brand2", logo="logoB2").save()
>>> Brand.objects.all().values()
<QuerySet [{'id': 1, 'name': 'brand1', 'logo': 'logoB1'}, {'id': 2, 'name': 'brand2', 'logo': 'logoB2'}]>
>>>
>>>
>>>
>>> Product(product_name = "p1")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/base.py", line 500, in __init__
    raise TypeError("%s() got an unexpected keyword argument '%s'" % (cls.__name__, kwarg))
TypeError: Product() got an unexpected keyword argument 'product_name'
>>> Product(product_name = "p1").save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/base.py", line 500, in __init__
    raise TypeError("%s() got an unexpected keyword argument '%s'" % (cls.__name__, kwarg))
TypeError: Product() got an unexpected keyword argument 'product_name'
>>>
>>>
>>> Product(name = "p1").save()
>>> Product(name = "p2", brand_id = 2).save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/base.py", line 482, in __init__
    _setattr(self, field.name, rel_obj)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py", line 219, in __set__
    self.field.remote_field.model._meta.object_name,
ValueError: Cannot assign "2": "Product.brand_id" must be a "Brand" instance.
>>> Product(name = "p2", brand_id_id = 2).save()
>>>
>>>
>>> Product(name = "p2", brand.objects.get(id=2)).save()
  File "<console>", line 1
SyntaxError: positional argument follows keyword argument
>>> Product(name = "p2", brand_id = brand.objects.get(id=2)).save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'brand' is not defined
>>> Product(name = "p2", brand_id = Brand.objects.get(id=2)).save()
>>>
>>>
>>>
>>> Product(name = "p2", brand_id = Brand.objects.get(id=2)).del()
  File "<console>", line 1
    Product(name = "p2", brand_id = Brand.objects.get(id=2)).del()
                                                               ^
SyntaxError: invalid syntax
>>> Product(name = "p2", brand_id = Brand.objects.get(id=2)).delete()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/base.py", line 932, in delete
    (self._meta.object_name, self._meta.pk.attname)
AssertionError: Product object can't be deleted because its id attribute is set to None.
>>> Product(name = "p2").delete()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/base.py", line 932, in delete
    (self._meta.object_name, self._meta.pk.attname)
AssertionError: Product object can't be deleted because its id attribute is set to None.
>>>
>>>
>>> Product(name = "p3", brand_id = Brand.objects.get(id=3)).save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 417, in get
    self.model._meta.object_name
sample.models.Brand.DoesNotExist: Brand matching query does not exist.
>>>
>>>
>>> Product(name = "p3", brand_id = Brand.objects.get(id=1)).save()
>>>
>>>
>>> Product(id=2, name = "p24", brand_id = Brand.objects.get(id=1)).save()
>>>
>>>
>>>
>>>
>>>
>>>
>>> Product.select_related(Brand)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: type object 'Product' has no attribute 'select_related'
>>>
>>> Product.select_related('Brand')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: type object 'Product' has no attribute 'select_related'
>>> Product.select_related
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: type object 'Product' has no attribute 'select_related'
>>>
>>>
>>> Product.select_related('name')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: type object 'Product' has no attribute 'select_related'
>>> Product.objects.select_related(Brand)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 1008, in select_related
    obj.query.add_select_related(fields)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/query.py", line 1950, in add_select_related
    for part in field.split(LOOKUP_SEP):
AttributeError: type object 'Brand' has no attribute 'split'
>>>
>>>
>>> Product.objects.select_related('id')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 252, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 276, in __iter__
    self._fetch_all()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 1261, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 57, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1124, in execute_sql
    sql, params = self.as_sql()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 483, in as_sql
    extra_select, order_by, group_by = self.pre_sql_setup()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 51, in pre_sql_setup
    self.setup_query()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 42, in setup_query
    self.select, self.klass_info, self.annotation_col_map = self.get_select()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 236, in get_select
    related_klass_infos = self.get_related_selections(select)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 837, in get_related_selections
    ", ".join(_get_field_choices()) or '(none)',
django.core.exceptions.FieldError: Non-relational field given in select_related: 'id'. Choices are: brand_id
>>>
>>>
>>> Product.objects.select_related('name')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 252, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 276, in __iter__
    self._fetch_all()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 1261, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 57, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1124, in execute_sql
    sql, params = self.as_sql()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 483, in as_sql
    extra_select, order_by, group_by = self.pre_sql_setup()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 51, in pre_sql_setup
    self.setup_query()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 42, in setup_query
    self.select, self.klass_info, self.annotation_col_map = self.get_select()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 236, in get_select
    related_klass_infos = self.get_related_selections(select)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 837, in get_related_selections
    ", ".join(_get_field_choices()) or '(none)',
django.core.exceptions.FieldError: Non-relational field given in select_related: 'name'. Choices are: brand_id
>>>
>>>
>>> Product.objects.select_related("name")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 252, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 276, in __iter__
    self._fetch_all()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 1261, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 57, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1124, in execute_sql
    sql, params = self.as_sql()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 483, in as_sql
    extra_select, order_by, group_by = self.pre_sql_setup()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 51, in pre_sql_setup
    self.setup_query()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 42, in setup_query
    self.select, self.klass_info, self.annotation_col_map = self.get_select()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 236, in get_select
    related_klass_infos = self.get_related_selections(select)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 837, in get_related_selections
    ", ".join(_get_field_choices()) or '(none)',
django.core.exceptions.FieldError: Non-relational field given in select_related: 'name'. Choices are: brand_id
>>>
>>> Product.objects.select_related("brand_id")
<QuerySet [<Product: Product object (2)>, <Product: Product object (4)>, <Product: Product object (3)>, <Product: Product object (1)>]>
>>>
>>> Product.objects.select_related("brand_id_id")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 252, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 276, in __iter__
    self._fetch_all()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 1261, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/query.py", line 57, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1124, in execute_sql
    sql, params = self.as_sql()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 483, in as_sql
    extra_select, order_by, group_by = self.pre_sql_setup()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 51, in pre_sql_setup
    self.setup_query()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 42, in setup_query
    self.select, self.klass_info, self.annotation_col_map = self.get_select()
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 236, in get_select
    related_klass_infos = self.get_related_selections(select)
  File "/Users/marie/miniconda3/envs/wehome_conda/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 957, in get_related_selections
    ', '.join(_get_field_choices()) or '(none)',
django.core.exceptions.FieldError: Invalid field name(s) given in select_related: 'brand_id_id'. Choices are: brand_id
>>>
>>>
>>> Product.objects.select_related("brand_id")
<QuerySet [<Product: Product object (2)>, <Product: Product object (4)>, <Product: Product object (3)>, <Product: Product object (1)>]>
>>>
>>> Product.objects.select_related("brand_id").values()
<QuerySet [{'id': 1, 'name': 'p1', 'image': '', 'brand_id_id': None}, {'id': 2, 'name': 'p24', 'image': '', 'brand_id_id': 1}, {'id': 3, 'name': 'p2', 'image': '', 'brand_id_id': 2}, {'id': 4, 'name': 'p3', 'image': '', 'brand_id_id': 1}]>
>>> Product.objects.select_related("brand_id").values()
<QuerySet [{'id': 1, 'name': 'p1', 'image': '', 'brand_id_id': None}, {'id': 2, 'name': 'p24', 'image': '', 'brand_id_id': 1}, {'id': 3, 'name': 'p2', 'image': '', 'brand_id_id': 2}, {'id': 4, 'name': 'p3', 'image': '', 'brand_id_id': 1}]>
>>>
>>>
>>>
>>>
>>>
profile
#의식의흐름 #순간순간 #생각의스냅샷

0개의 댓글