Skip to content

[검수] 220211 generic relation import 누락 반영 #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 121 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
a80f68e
first commit
leehosung Sep 3, 2018
aa31e26
update index.rst
leehosung Sep 3, 2018
ac0ccd4
Merge pull request #1 from 8percent/180904-first-test
leehosung Sep 3, 2018
4e96357
테스트 목적으로 업데이트
leehosung Sep 4, 2018
f3738ab
order_by 부분 번역
initialkommit Sep 22, 2018
0ca0b15
union 부분 번역
initialkommit Sep 22, 2018
97cfcda
ADD: 1.one_to_on TO 4.self-referencing
anohk Sep 25, 2018
dfd13d4
CHG: modify syntax
anohk Sep 25, 2018
b62b207
CHG: modify syntax
anohk Sep 25, 2018
2d81868
ADD: 번역 추가
anohk Sep 26, 2018
7dfdeb5
modify syntax
anohk Sep 26, 2018
1a128ec
번역 추가
anohk Sep 26, 2018
be525e5
modify syntax
anohk Sep 26, 2018
bd97ba1
Translate Queryset ordering
Kirade Sep 26, 2018
ed47b2e
Translate rest
Kirade Sep 26, 2018
f684954
Update f_query.rst
hshwang-jdlab Sep 26, 2018
2b10a64
Update filefield.rst
hshwang-jdlab Sep 26, 2018
17439a0
Update join.rst
hshwang-jdlab Sep 26, 2018
33b94e3
Update second_largest.rst
hshwang-jdlab Sep 26, 2018
e9ff7d1
Update distinct.rst
hshwang-jdlab Sep 26, 2018
60c9167
Update duplicate.rst
hshwang-jdlab Sep 26, 2018
824f9b0
annotated field에 code block 깨진 거 처리
initialkommit Sep 27, 2018
4e4b472
code block 사이에 whitespace 추가
initialkommit Sep 27, 2018
6f0814c
code block 처리
initialkommit Sep 27, 2018
7ca4e29
code block 처리
initialkommit Sep 27, 2018
38885dd
code block 처리
initialkommit Sep 27, 2018
7525409
code block 처리
initialkommit Sep 27, 2018
f8d6c5f
Merge pull request #5 from 8percent/tips
bakyeono Sep 29, 2018
fcda676
Merge pull request #2 from 8percent/TRANSLATE-order-by
bakyeono Sep 29, 2018
940e561
Merge pull request #3 from 8percent/relationship
bakyeono Sep 29, 2018
0e018cc
Merge pull request #4 from 8percent/generic_fk
bakyeono Sep 29, 2018
3d53508
Merge branch 'master' into jaeyoung
bakyeono Sep 29, 2018
463ae43
Merge pull request #6 from 8percent/jaeyoung
bakyeono Sep 29, 2018
49efb6b
Merge pull request #7 from hshwang-jdlab/patch-2
bakyeono Sep 29, 2018
4e8a6a2
Merge pull request #8 from 8percent/TRANSLATE-union
bakyeono Sep 29, 2018
ad174b7
README, index
bakyeono Sep 29, 2018
6930675
introduction
bakyeono Sep 29, 2018
13adc11
query
bakyeono Sep 29, 2018
7ec7618
or_query
bakyeono Sep 29, 2018
c73efa3
and_Query
bakyeono Sep 29, 2018
afbdf39
notequal_query
bakyeono Sep 29, 2018
797fac1
union
bakyeono Sep 29, 2018
43e8358
Django ORM cookbook Chapter 2.14 부터 Chapter 2.17까지 번역.
teekey-dev Sep 29, 2018
ffa5099
select_some_fields
bakyeono Sep 29, 2018
ffbb4d1
subquery
bakyeono Sep 29, 2018
4324bd7
subquery
bakyeono Sep 29, 2018
3fa19af
f_query
bakyeono Sep 29, 2018
e28bf1e
filefield
bakyeono Sep 29, 2018
744cd58
join
bakyeono Sep 29, 2018
5ddeabe
second_largest 1
bakyeono Sep 29, 2018
fe1902f
second_largest 1
bakyeono Sep 29, 2018
f9e80c4
Merge pull request #9 from hegrecom/2_14_to_2_17
bakyeono Sep 29, 2018
58c0981
second_largest 2
bakyeono Sep 29, 2018
3baf91f
duplicate
bakyeono Sep 29, 2018
421180a
distinct
bakyeono Sep 29, 2018
c1d4a16
query_relatedtool
bakyeono Sep 29, 2018
0320bc0
aggregation
bakyeono Sep 29, 2018
1cd4c7f
random
bakyeono Sep 29, 2018
d8e2fe6
func_expressions
bakyeono Sep 29, 2018
60a65f8
Merge branch 'master' of github.com:8percent/django-orm-cookbook-ko
bakyeono Sep 29, 2018
74f46ea
2부까지 퇴고
bakyeono Sep 29, 2018
2923068
introduction
bakyeono Sep 29, 2018
6ed7cc8
오타, 문구 수정
bakyeono Sep 29, 2018
d071946
singleton
bakyeono Sep 29, 2018
b2bc04d
truncate
bakyeono Sep 29, 2018
54ea6bc
signals
bakyeono Sep 29, 2018
ca47733
datetime
bakyeono Sep 29, 2018
e0f1601
fix: truncate
bakyeono Sep 29, 2018
bfb034c
join 원어 병기
bakyeono Sep 30, 2018
7c865a7
auto increment 병기
bakyeono Sep 30, 2018
4ee1165
signals
bakyeono Sep 30, 2018
e2e02d2
copy
bakyeono Sep 30, 2018
382bc9a
distinct
bakyeono Sep 30, 2018
7d234ea
관대한 -> 선한
bakyeono Sep 30, 2018
0d66fa4
asc_or_desc
bakyeono Sep 30, 2018
6fcf661
case_insensitive
bakyeono Sep 30, 2018
1332f03
order_by_related_model
bakyeono Sep 30, 2018
db67599
order_by_related_model
bakyeono Sep 30, 2018
c96fb00
order_by_annotated_field
bakyeono Sep 30, 2018
0fbc17d
one_to_one
bakyeono Sep 30, 2018
9bffffc
one_to_one
bakyeono Sep 30, 2018
6b34927
one_to_many
bakyeono Sep 30, 2018
aa38e06
many_to_many
bakyeono Sep 30, 2018
4920031
self_fk
bakyeono Sep 30, 2018
f38ac94
existing_database
bakyeono Sep 30, 2018
a8fc533
database_view
bakyeono Sep 30, 2018
6bfff1a
Merge pull request #10 from 8percent/퇴고-1부-2부
bakyeono Sep 30, 2018
a980114
Merge branch 'master' into 퇴고-4부-5부
bakyeono Sep 30, 2018
de1387b
generic_models
bakyeono Sep 30, 2018
77bcc9f
generic_models
bakyeono Sep 30, 2018
c978b7e
table_names
bakyeono Sep 30, 2018
c4563ad
column_name
bakyeono Sep 30, 2018
aa233f1
index
bakyeono Sep 30, 2018
68eaccb
null_vs_blank
bakyeono Sep 30, 2018
cc1ac24
uuid
bakyeono Sep 30, 2018
0ebbf2b
slugfield
bakyeono Sep 30, 2018
418388f
multiple_databases
bakyeono Sep 30, 2018
75f5652
numqueries
bakyeono Sep 30, 2018
343a026
keepdb
bakyeono Sep 30, 2018
8931c98
refresh_from_db
bakyeono Sep 30, 2018
9f4da3b
Merge pull request #11 from 8percent/퇴고-4부-5부
bakyeono Sep 30, 2018
b025060
Update README.md
bakyeono Sep 30, 2018
a9b86ae
Update query.rst
hshwang-jdlab Sep 30, 2018
f4f6184
Merge pull request #12 from hshwang-jdlab/patch-3
bakyeono Sep 30, 2018
a842e1f
조판 오류 수정 및 2차 퇴고
bakyeono Sep 30, 2018
faaada9
Merge pull request #13 from 8percent/조판오류수정
bakyeono Sep 30, 2018
9a0fdf5
NEW: PDF 빌드 설정 및 스크립트
leehosung Sep 30, 2018
b3d3151
CHG: 공백 없애기
leehosung Oct 1, 2018
14431b9
CHG: 북커버 제외하기
leehosung Oct 1, 2018
7dfb1c6
FIX: typo
leehosung Oct 1, 2018
118f3df
Merge pull request #15 from 8percent/181001_typo
bakyeono Oct 1, 2018
d2aebad
Merge pull request #14 from 8percent/181001_pdf
bakyeono Oct 1, 2018
02bcf00
Syntax highlighting
mingrammer Oct 2, 2018
5819349
Merge pull request #16 from mingrammer/master
leehosung Oct 2, 2018
a4100a5
FIX: typo
9bow Oct 2, 2018
b4fbbe4
FIX: typo
9bow Oct 2, 2018
702b747
Merge pull request #17 from 9bow/master
bakyeono Oct 3, 2018
bf0d941
FIX: typo
lee-seul Oct 6, 2018
dbbb321
깨진 code block 수정
lee-seul Oct 6, 2018
159ade0
Merge pull request #18 from lee-seul/master
bakyeono Oct 7, 2018
e7ef160
ADD: import 누락 추가
kyungjunleeme Feb 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
418 changes: 212 additions & 206 deletions README.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/aggregation.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
How to group records in Django ORM?
========================================
기록된 항목의 집계를 구할 수 있나요?
==================================================================

Grouping of records in Django ORM can be done using aggregation functions like :code:`Max`, :code:`Min`, :code:`Avg`, :code:`Sum`. Django queries help to create, retrieve, update and delete objects. But sometimes we need to get aggregated values from the objects. We can get them by example shown below ::
장고 ORM을 이용해 항목을 생성·조회·갱신·삭제할 수 있지만, 때로는 항목들의 집계값을 구하고 싶을 때가 있습니다. 장고 ORM에는 SQL의 일반적인 집계 기능을 수행하는 :code:`Max`, :code:`Min`, :code:`Avg`, :code:`Sum` 등의 함수가 있습니다. 다음은 이 집계 함수를 이용하는 예입니다. ::

>>> from django.db.models import Avg, Max, Min, Sum, Count
>>> User.objects.all().aggregate(Avg('id'))
Expand Down
28 changes: 11 additions & 17 deletions docs/and_query.rst
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
How to do AND queries in Django ORM?
++++++++++++++++++++++++++++++++++++++++++++++++++
AND 연산으로 여러 조건을 모두 만족하는 항목을 구하려면 어떻게 하나요?
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: usertable.png

If you are using :code:`django.contrib.auth`, you will have a table called :code:`auth_user`. It will have fields as :code:`username`, :code:`first_name`, :code:`last_name` and more.
장고의 사용자 계정 관리 앱인 :code:`django.contrib.auth` 를 사용하면 데이터베이스에 :code:`auth_user` 라는 표가 생성됩니다. 이 표에는 :code:`username`, :code:`first_name`, :code:`last_name` 등의 열이 있습니다.

:code:`AND` 연산으로 여러 조건을 모두 만족하는 행을 구해야 하는 경우가 많습니다. 이름이 'R'로 시작하고 성이 'D'로 시작하는 모든 사용자를 구한다고 해 봅시다.

You would frequently need to want to perform AND operation, to find querysets which match multiple criteria.

Say you want to find users with :code:`firstname` starting with 'R' AND :code:`last_name` starting with 'D'.

Django provides three options.
장고에서는 다음 세 방법으로 구할 수 있습니다.

- :code:`filter(<condition_1>, <condition_2>)`
- :code:`queryset_1 & queryset_2`
- :code:`filter(Q(<condition_1>) & Q(<condition_2>))`


The query in detail
질의문 살펴보기
-----------------------


Our SQL query for the above condition will look something like

.. code-block:: sql
위 조건의 SQL 질의문은 다음과 같이 생성됩니다. ::

SELECT username, first_name, last_name, email FROM auth_user WHERE first_name LIKE 'R%' AND last_name LIKE 'D%';

.. image:: sqluser_result2.png

The default way to combine multiple conditions in :code:`filter` is :code:`AND`, so you can just do.
장고 쿼리셋의 :code:`filter` 메서드에서 여러 조건을 결합하는 방법은 기본적으로 :code:`AND` 방식입니다. 따라서 다음과 같이 조건을 그냥 나열하면 됩니다.

.. code-block:: python

Expand All @@ -38,7 +32,7 @@ The default way to combine multiple conditions in :code:`filter` is :code:`AND`,
last_name__startswith='D'
)

Alternatively, you can explicitly use the `&` operator on querysets.
하지만 `&` 연산자를 사용하여 쿼리셋을 명시적으로 결합할 수도 있습니다.

.. code-block:: python

Expand All @@ -48,7 +42,7 @@ Alternatively, you can explicitly use the `&` operator on querysets.
last_name__startswith='D'
)

For complete customisability, you can use the :code:`Q` objects.
복잡한 질의를 수행할 수 있도록 도와주는 :code:`Q` 객체를 이용하여 조건을 명시해도 됩니다.

.. code-block:: python

Expand All @@ -61,7 +55,7 @@ For complete customisability, you can use the :code:`Q` objects.
queryset_1
<QuerySet [<User: Ricky>, <User: Ritesh>, <User: rishab>]>

You can look at the generated query and verify that they are all same.
언제나 실제로 생성되는 SQL 질의문을 확인하여 검증하는 것이 도움이 됩니다.

.. code-block:: ipython

Expand Down
16 changes: 7 additions & 9 deletions docs/asc_or_desc.rst
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
How to order a queryset in ascending or descending order?
=============================================================
쿼리셋을 오름차순/내림차순으로 정렬할 수 있나요?
======================================================================

Ordering of the queryset can be achieved by :code:`order_by` method. We need to pass the field on which we need to Order (ascending/descending) the result.
Query looks like this
:code:`order_by` 메서드로 쿼리셋을 정렬할 수 있습니다. 기준 필드를 지정해 오름차순 혹은 내림차순으로 정렬할 수 있습니다. 다음 코드를 살펴보세요.

.. code-block:: ipython

>>> User.objects.all().order_by('date_joined') # For ascending
>>> User.objects.all().order_by('date_joined') # 오름차순
<QuerySet [<User: yash>, <User: John>, <User: Ricky>, <User: sharukh>, <User: Ritesh>, <User: Billy>, <User: Radha>, <User: Raghu>, <User: rishab>, <User: johny>, <User: paul>, <User: johny1>, <User: alien>]>
>>> User.objects.all().order_by('-date_joined') # For descending; Not '-' sign in order_by method
>>> User.objects.all().order_by('-date_joined') # 내림차순
<QuerySet [<User: alien>, <User: johny1>, <User: paul>, <User: johny>, <User: rishab>, <User: Raghu>, <User: Radha>, <User: Billy>, <User: Ritesh>, <User: sharukh>, <User: Ricky>, <User: John>, <User: yash>]>

You can pass multiple fields to :code:`order_by`
기준 필드를 여러 개 지정할 수도 있습니다.

.. code-block:: ipython

User.objects.all().order_by('date_joined', '-last_login')

Looking at the SQL

SQL 질의문은 다음과 같습니다.

.. code-block:: sql

Expand Down
12 changes: 6 additions & 6 deletions docs/case_insensitive.rst
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
How to order a queryset in case insensitive manner?
대문자·소문자를 구별하지 않고 정렬하려면 어떻게 하나요?
============================================================

.. image:: usertable2.png

Whenever we try to do :code:`order_by` with some string value, the ordering happens alphabetically and w.r.t case. Like
:code:`order_by` 메서드로 쿼리셋을 정렬할 때, 텍스트 필드를 기준으로 하면 알파벳의 대문자·소문자를 구분하여 정렬이 수행됩니다. 다음 예에서 보듯, 대문자에 소문자보다 높은 우선순위가 부여됩니다.

.. code-block:: ipython

>>> User.objects.all().order_by('username').values_list('username', flat=True)
<QuerySet ['Billy', 'John', 'Radha', 'Raghu', 'Ricky', 'Ritesh', 'johny', 'johny1', 'paul', 'rishab', 'sharukh', 'sohan', 'yash']>

If we want to order queryset in case insensitive manner, we can do like this . ::
텍스트 필드에서 대문자·소문자를 구별하지 않고 정렬하려면 다음과 같이 :code:`Lower` 를 사용하면 됩니다.

.. code-block:: ipython

>>> from django.db.models.functions import Lower
>>> User.objects.all().order_by(Lower('username')).values_list('username', flat=True)
<QuerySet ['Billy', 'John', 'johny', 'johny1', 'paul', 'Radha', 'Raghu', 'Ricky', 'rishab', 'Ritesh', 'sharukh', 'sohan', 'yash']>

Alternatively, you can annotate with :code:`Lower` and then order on annotated field.
:code:`annotate` 메서드로 :code:`Lower` 를 적용한 열을 준비하고, 그 열을 기준으로 정렬하는 방법도 가능합니다.

.. code-block:: python

User.objects.annotate(
uname=Lower('username')
).order_by('uname').values_list('username', flat=True)
lower_name=Lower('username')
).order_by('lower_name').values_list('username', flat=True)
8 changes: 4 additions & 4 deletions docs/column_name.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
How to specify the column name for model field?
=====================================================
모델 필드의 데이터베이스 열 이름을 지정할 수 있나요?
=============================================================================

Naming of a column in the model can be achieved py passing a :code:`db_column` parameter with some name. If we don't pass this parameter django creates a column with the field name which we give. ::
모델 필드가 가리키는 데이터베이스의 열 이름을 지정하려면 필드 인스턴스의 초기화 매개변수 :code:`db_column` 에 원하는 이름을 전달하면 됩니다. 이 매개변수에 인자를 전달하지 않으면 필드 이름과 동일한 이름이 사용됩니다. ::

class ColumnName(models.Model):
a = models.CharField(max_length=40,db_column='column1')
Expand All @@ -12,4 +12,4 @@ Naming of a column in the model can be achieved py passing a :code:`db_column` p

.. image:: db_column.png

Above we can :code:`db_column` has higher priority over :code:`field name`. First column is named as column1 but not as a.
위 예에서 보듯, :code:`db_column` 으로 지정한 이름이 필드 이름보다 우선순위가 높습니다. 첫 번째 열의 이름이 a가 아니라 column1로 지어졌습니다.
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
'extraclassoptions': 'openany,oneside'
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'DjangoORMCookbook.tex', 'Django ORM Cookbook Documentation',
'Agiliq', 'manual'),
(master_doc, 'DjangoORMCookbook.tex', '장고 ORM 요리책',
'Agiliq/8퍼센트', 'manual'),
]


Expand Down
6 changes: 3 additions & 3 deletions docs/copy.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
How to copy or clone an existing model object?
기존에 저장된 행을 복사해 새로 저장하는 방법은 무엇인가요?
========================================================================

There is no built-in method for copying model instances, it is possible to create new instance with all fields values copied.
장고 ORM에는 모델 인스턴스를 복사하는 내장 메서드가 없습니다. 하지만 모든 필드의 값을 복사하여 새 인스턴스를 만들고 새로 저장하는 것은 어렵지 않습니다.

If an instance is saved with instance's :code:`pk` set to :code:`None`, the instance is used to create a new record in the DB. That means every field other than the :code:`PK` is copied.
모델 인스턴스를 저장할 때, :code:`pk` 필드 값이 :code:`None` 으로 지정되어 있으면 데이터베이스에 새 행으로 저장됩니다. :code:`pk` 외의 모든 필드 값은 그대로 복제됩니다.

.. code-block:: ipython

Expand Down
29 changes: 17 additions & 12 deletions docs/database_view.rst
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
How to add a model for a database view?
===============================================
데이터베이스 뷰에 대응하는 모델을 정의할 수 있나요?
==========================================================================

A database view is a searchable object in a database that is defined by a query. Though a view doesn’t store data, some refer to a views as “virtual tables,” you can query a view like you can a table. A view can combine data from two or more table, using joins, and also just contain a subset of information. This makes them convenient to abstract, or hide, complicated queries.
데이터베이스 뷰는 데이터베이스 내에서 조회할 수 있도록 질의문으로 정의된 객체입니다. 뷰가 데이터를 물리적으로 저장하는 것은 아니지만, 실제 표와 같이 조회할 수 있기 때문에 '가상 표'라고 불리기도 합니다. 뷰는 여러 표를 결합(JOIN)한 정보를 보여줄 수도 있고, 한 표의 부분 집합만을 보여줄 수도 있습니다. 이를 활용하면 복잡한 질의문을 감추고 필요한 정보를 쉽게 조회하는 인터페이스를 만들 수 있습니다.

In our SqliteStuio we can see 26 tables and no views.
다음 스크린샷은 데이터베이스를 SQLiteStudio라는 프로그램으로 열어 본 모습입니다. 표가 26개 있고, 뷰는 없습니다.

.. image:: before_view.png

Lets create a simple view. ::
SQL 질의문을 실행하여 간단한 뷰를 생성하겠습니다.

create view temp_user as
select id, first_name from auth_user;
.. code-block:: sql

After the view is created, we can see 26 tables and 1 view.
create view temp_user as
select id, first_name
from auth_user;

뷰가 생성되어 표 26개와 뷰 1개가 있습니다.

.. image:: after_view.png

We can create its related model in our app, by :code:`managed = False` and :code:`db_table="temp_user"` ::
장고 앱에서는 모델을 정의할 때 메타(:code:`Meta`) 클래스에 :code:`managed = False`, :code:`db_table="temp_user"` 와 같이 옵션을 설정하여 뷰를 가리키는 모델로 사용할 수 있습니다. ::

class TempUser(models.Model):
first_name = models.CharField(max_length=100)
Expand All @@ -25,14 +28,16 @@ We can create its related model in our app, by :code:`managed = False` and :code
managed = False
db_table = "temp_user"

// We can query the newly created view similar to what we do for any table.
>>> # 실제 표와 마찬가지로 뷰를 조회할 수 있습니다.
>>> TempUser.objects.all().values()
<QuerySet [{'first_name': 'Yash', 'id': 1}, {'first_name': 'John', 'id': 2}, {'first_name': 'Ricky', 'id': 3}, {'first_name': 'Sharukh', 'id': 4}, {'first_name': 'Ritesh', 'id': 5}, {'first_name': 'Billy', 'id': 6}, {'first_name': 'Radha', 'id': 7}, {'first_name': 'Raghu', 'id': 9}, {'first_name': 'Rishabh', 'id': 10}, {'first_name': 'John', 'id': 11}, {'first_name': 'Paul', 'id': 12}, {'first_name': 'Johny', 'id': 13}, {'first_name': 'Alien', 'id': 14}]>
// You cannot insert new reord in a view.
>>> # 그러나 뷰에 기록은 하지 못합니다.
>>> TempUser.objects.create(first_name='Radhika', id=15)
Traceback (most recent call last):
...
django.db.utils.OperationalError: cannot modify temp_user because it is a view

For view having union operation refer to :
union 연산이 있는 뷰는 아래 주소의 문서(Django Admin Cookbook)를 참고하세요.

http://books.agiliq.com/projects/django-admin-cookbook/en/latest/database_view.html?highlight=view

9 changes: 5 additions & 4 deletions docs/datetime.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
How to convert string to datetime and store in database?
============================================================
시간 정보를 다른 양식으로 변환하여 데이터베이스에 저장하려면 어떻게 해야 하나요?
=============================================================================================

We can convert a date-string and store it in the database using django in many ways. Few of them are discussed below.
Lets say we have a date-string as "2018-03-11" we can not directly store it to our date field, so we can use some dateparser or python library for it. ::
장고에서 시간을 나타내는 텍스트를 다른 양식의 텍스트로 변환하여 데이터베이스에 저장하는 방법은 여러 가지가 있습니다. 몇 가지만 소개하겠습니다.

"2018-03-11"이라는 시간 텍스트가 있는데, 이 양식으로는 데이터베이스에 저장할 수 없다고 가정합시다. 아래와 같이 장고의 dateparser 모듈이나 파이썬 표준 라이브러리를 이용하여 날짜 양식을 변환할 수 있습니다. ::

>>> user = User.objects.get(id=1)
>>> date_str = "2018-03-11"
Expand Down
7 changes: 3 additions & 4 deletions docs/distinct.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
How to find distinct field values from queryset?
쿼리셋에서 고유한 필드 값을 가진 항목은 어떻게 구하나요?
========================================================================

.. image:: usertable2.png

You want to find users whose names have not been repeated. You can do this like this
이름이 다른 사용자와 겹치지 않은 사용자를 찾는다고 합시다. 다음과 같이 구할 수 있습니다.

.. code-block:: python

Expand All @@ -14,6 +14,5 @@ You want to find users whose names have not been repeated. You can do this like
).filter(name_count=1)
records = User.objects.filter(first_name__in=[item['first_name'] for item in distinct])

This is different from :code:`User.objects.distinct("first_name").all()`, which will pull up the first record when it encounters a distinct :code:`first_name`.

한편, :code:`User.objects.distinct("first_name").all()` 와 같은 코드는 고유한 :code:`first_name` 을 가진 사용자별로 첫번째 사용자를 구하는 코드입니다. 위 코드와는 실행 결과가 다릅니다.

11 changes: 5 additions & 6 deletions docs/duplicate.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
Find rows which have duplicate field values
==============================================
특정 열의 값이 동일한 항목은 어떻게 찾나요?
==========================================================

.. image:: usertable2.png

Say you want all users whose :code:`first_name` matches another user.

You can find duplicate records using the technique below.
:code:`first_name` 이 서로 동일한 사용자들을 구한다고 합시다. 특정 열에서 중복된 값을 찾을 때는 아래와 같이 :code:`Count` 를 구한 뒤 중복 수를 기준으로 골라내면 됩니다.

.. code-block:: python

Expand All @@ -15,7 +13,8 @@ You can find duplicate records using the technique below.
>>> duplicates
<QuerySet [{'first_name': 'John', 'name_count': 3}]>

If you need to fill all the records, you can do
위와 같이 중복 값을 구했으면, 이 값을 가진 항목을 아래와 같이 구할 수 있습니다.


.. code-block:: python

Expand Down
10 changes: 5 additions & 5 deletions docs/existing_database.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
How to convert existing databases to Django models?
=====================================================
기존 데이터베이스를 장고 모델로 옮길 수 있나요?
================================================================================

Django comes with a utility called :code:`inspectdb` that can create models by introspecting an existing database. You can view the output by running this command ::
장고에는 기존 데이터베이스를 분석하여 그에 맞는 모델을 생성해주는 :code:`inspectdb` 명령이 있습니다. 셸에서 다음 명령을 실행하여 결과를 확인할 수 있습니다. ::

$ python manage.py inspectdb

Befor running this you will have to configure your database in the :code:`settings.py` file. The result will be a file containing a model for each table. You may want to save that file ::
이 명령을 실행하려면 먼저 :code:`settings.py` 파일에 분석하려는 데이터베이스의 접속 정보를 설정해 두어야 합니다. 출력 결과는 생성된 모델의 파이썬 코드입니다. 코드를 파이썬 모듈 파일로 저장하려면 다음과 같이 셸의 스트림 리디렉션 기능을 이용합니다. ::

$ python manage.py inspectdb > models.py

The output file will be saved to your current directory. Move that file to the correct app and you have a good starting point for further customizations.
위 명령을 실행하면 분석된 모델이 파이썬 모듈 파일로 현재 디렉토리에 저장될 것입니다. 이 파일을 앱의 올바른 위치로 옮긴 뒤, 적절히 수정하여 사용하면 됩니다.
Loading