You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: es/django_orm/README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,13 +93,13 @@ Ahora puedes divertirte un poco y añadir más posts para ver cómo funciona. A
93
93
Una parte importante de los QuerySets es la habilidad para filtrarlos. Digamos que queremos encontrar todos los posts cuyo autor es el User ola. Usaremos `filter` en vez de `all` en `Post.objects.all()`. En los paréntesis estableceremos qué condición o conduciones deben cumplirse por un post del blog para terminar en nuestro queryset. En nuestro caso sería `author` es igual a `me`. La forma de escribirlo en Django es: `author=me`. Ahora nuestro bloque de código se ve como esto:
94
94
95
95
>>> Post.objects.filter(author=me)
96
-
[<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]
96
+
<QuerySet [<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]>
97
97
98
98
99
99
¿O tal vez querramos ver todos los posts que contengan la palabra 'title' en el campo `title`?
100
100
101
101
>>> Post.objects.filter(title__contains='title')
102
-
[<Post: Sample title>, <Post: 4th title of post>]
102
+
<QuerySet [<Post: Sample title>, <Post: 4th title of post>]>
103
103
104
104
105
105
> **Nota** Hay dos guiones bajos (`_`) entre `title` y `contains`. Django ORM utiliza esta sintaxis para separar los nombres de los campos ("title") y operaciones o filtros ("contains"). Si sólo utilizas un guión bajo, obtendrás un error como "FieldError: Cannot resolve keyword title_contains".
@@ -123,21 +123,21 @@ Desafortunadamente, ninguno de nuestros posts han sido publicados todavía. ¡Va
123
123
Ahora intenta obtener la lista de posts publicados nuevamente (presiona la tecla con la flecha hacia arriba 3 veces y presiona Enter):
Copy file name to clipboardExpand all lines: es/django_templates/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Prueba esto en tu plantilla `blog/templates/blog/post_list.html` (reemplaza el s
26
26
27
27
Como puedes ver, todo lo que obtenemos es esto:
28
28
29
-
[<Post: Mi segundo post>, <Post: Mi primer post>]
29
+
<QuerySet [<Post: Mi segundo post>, <Post: Mi primer post>]>
30
30
31
31
32
32
Esto significa que Django lo entiende como una lista de objetos. ¿Recuerdas de **Introducción a Python** cómo podemos mostrar listas? Sí, ¡con los ciclos for! En una plantilla de Django, lo haces de esta manera:
Copy file name to clipboardExpand all lines: hu/django_orm/README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,14 +95,14 @@ A móka kedvéért hozz létre még 2-3 posztot, hogy lásd, hogyan működik. H
95
95
A QuerySet-ek egyik nagy előnye, hogy filterezhetjük (szűrhetjük) őket. Mondjuk le szeretnénk kérdezni az összes posztot, amit az ola User írt. Itt a `filter`-t fogjuk használni az `all` helyett a `Post.objects.all()`-ban. A zárójelek között megadhatjuk, hogy milyen feltétel(ek)nek kell teljesülnie ahhoz, hogy egy blogposzt bekerülhessen a querysetünkbe. Ebben az esetben az `author` (szerző) egyenlő `me`-vel (én). Ezt a Django-ban így írjuk le: `author=me`. Most így néz ki a kódunk:
96
96
97
97
>>> Post.objects.filter(author=me)
98
-
[<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]
98
+
<QuerySet [<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]>
99
99
100
100
101
101
102
102
És ha össze szeretnénk gyűjteni minden olyan posztot, aminek a `title` (cím) mezőjében szerepel a 'title' szó?
103
103
104
104
>>> Post.objects.filter(title__contains='title')
105
-
[<Post: Sample title>, <Post: 4th title of post>]
105
+
<QuerySet [<Post: Sample title>, <Post: 4th title of post>]>
106
106
107
107
108
108
> **Note** A `title` és a `contains` (vagyis 'tartalmaz') között két underscore karakter (`_`) van. A Django ORM ezt a szintaxist használja arra, hogy elkülönítse a mezők neveit ("title") a műveletektől vagy filterektől ("contains"). Ha csak egy underscore-t használt, egy ilyen hibát fogsz kapni: "FieldError: Cannot resolve keyword title_contains" (kb "Mezőhiba: a title_contains kulcsszó nem található").
@@ -126,21 +126,21 @@ Aztán közzétesszük a `publish` methoddal!
126
126
Most próbáld meg újra lekérdezni a közzétett posztok listáját (nyomd meg háromszor a felfelé nyilat, és nyomj `enter`t):
A QuerySetek segítségével sorba is rendezheted az objektumok listáját. Először próbáljuk meg a létrehozás dátuma (`created_date` mező) alapján rendezni őket:
135
135
136
136
>>> Post.objects.order_by('created_date')
137
-
[<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]
137
+
<QuerySet [<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]>
138
138
139
139
140
140
Meg is fordíthatjuk a sorrendet, ha az elejére egy `-` jelet teszünk:
141
141
142
142
>>> Post.objects.order_by('-created_date')
143
-
[<Post: 4th title of post>, <Post: My 3rd post!>, <Post: Post number 2>, <Post: Sample title>]
143
+
<QuerySet [<Post: 4th title of post>, <Post: My 3rd post!>, <Post: Post number 2>, <Post: Sample title>]>
Copy file name to clipboardExpand all lines: hu/django_templates/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Próbáld ki a `blog/templates/blog/post_list.html` template-ben. Cserélj ki mi
26
26
27
27
Ahogy látod, ez minden, amink van:
28
28
29
-
[<Post: My second post>, <Post: My first post>]
29
+
<QuerySet [<Post: My second post>, <Post: My first post>]>
30
30
31
31
32
32
Ez azt jelenti, hogy a Django objektumok listájaként értelmezi. Emlékszel a **Bevezetés a Python-ba** című fejezetből, hogy hogyan jelenítünk meg listákat? Igen, for loop-okkal! Egy Django template-ben ezt így tudod megtenni:
@@ -103,4 +103,4 @@ Olyan, mint a varázslat? Büszkék vagyunk Rád! Hagy ott egy kicsit a gépet,
Copy file name to clipboardExpand all lines: it/django_orm/README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,13 +95,13 @@ Ora puoi divertirti un po' ed aggiungere altri post per vedere come funziona. Ag
95
95
Larga parte parte dei QuerySet consiste nell'abilità di filtrarli. Diciamo che vogliamo trovare tutti i post che hanno come autore l'Utente ola. Useremo `filter` invece di `all` in `Post.objects.all()`. Tra parentesi affermeremo le condizioni che un blog post deve soddisfare per finire nel nostro queryset. Nella nostra situazione è `autore` che è uguale a `me`. Il modo di scriverlo in Django è `autore=me`. Ora il nostro pezzo di codice ha questo aspetto:
96
96
97
97
>>> Post.objects.filter(author=me)
98
-
[<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]
98
+
<QuerySet [<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]>
99
99
100
100
101
101
O magari vogliamo vedere tutti i post che contengono la parola 'titolo' nel campo `titolo`?
102
102
103
103
>>> Post.objects.filter(title__contains='title')
104
-
[<Post: Sample title>, <Post: 4th title of post>]
104
+
<QuerySet [<Post: Sample title>, <Post: 4th title of post>]>
105
105
106
106
107
107
> **Nota** ci sono due caratteri di sottolineatura (`_`) tra `titolo` e `contains`. L'ORM di Django usa questa sintassi per separare i nomi dei campi ("titolo") ed operazioni o filtri ("contiene"). Se usi solo un carattere di sottolineatura, otterrai un errore come "FieldError: non è possibile risolvere la parola chiave title_contains".
@@ -125,21 +125,21 @@ Ora pubblicalo con il nostro metodo `publish`!
125
125
Ora cerca di ottenere di nuovo l'elenco dei post pubblicati (premere il pulsante di freccia in su 3 volte e premere `invio`):
Copy file name to clipboardExpand all lines: it/django_templates/README.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Prova questo nel tuo template `blog/templates/blog/post_list.html`. Sostituisci
26
26
27
27
Come vedi, quello che abbiamo è:
28
28
29
-
[<Post: My second post>, <Post: My first post>]
29
+
<QuerySet [<Post: My second post>, <Post: My first post>]>
30
30
31
31
32
32
Significa che Django lo vede come una lista di oggetti. Ricordi dalla **Introduzione a Python** come possiamo rendere visibili le liste? Sì, con for loops! In un template Django si fanno così:
@@ -102,4 +102,4 @@ Funziona come un incantesimo? Ne siamo fieri! Staccati dal computer per un po',
Copy file name to clipboardExpand all lines: ko/django_orm/README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,13 +95,13 @@ PythonAnywhere가 아닌 로컬 컨솔에서 아래 명령을 입력하세요. :
95
95
쿼리셋의 중요한 기능은 데이터를 필터링하는 거에요. 예를 들어, 우리는 ola라는 User가 작성한 모든 글을 찾고 싶다고 해볼게요. 이런 경우 `Post.objects.all()`에서 `all` 대신, `filter`를 사용합니다. 쿼리셋 안에 있는 괄호 안에 우리가 원하는 조건(들)을 넣어줄 거에요. 지금 이 경우에는 `author`가 `me`인 조건을 넣어야겠죠. 이걸 장고로 표현한다면 `author=me`가 됩니다. 이제 이 조건이 반영된 코드를 볼까요. :
96
96
97
97
>>> Post.objects.filter(author=me)
98
-
[<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]
98
+
<QuerySet [<Post: Sample title>, <Post: Post number 2>, <Post: My 3rd post!>, <Post: 4th title of post>]>
99
99
100
100
101
101
또는 모든 글들 중, `제목(title)`에 'title'이라는 글자가 들어간 글들만을 뽑아내서 보고 싶다면요?
Copy file name to clipboardExpand all lines: pl/django_orm/README.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,13 +95,13 @@ Możesz teraz się pobawić i utworzyć więcej wpisów, żeby zobaczyć, jak to
95
95
Niezmiernie istotną cechą QuerySetów jest możliwość ich filtrowania. Dajmy na to, że chciałybyśmy znaleźć wszystkie wpisy dodane przez użytkowniczkę (User) o nazwie ola. Skorzystamy z metody `filter` zamiast `all` w `Post.objects.all()`. W nawiasach wpiszemy jeden lub więcej warunków, które muszą zostać spełnione, żeby nasz wpis znalazł się w QuerySecie. W naszej sytuacji chcemy, by `author` (autor) odpowiadał zmiennej `me`. W Django zapisujemy to tak: `author=me`. Teraz nasz kawałek kodu wygląda mniej więcej tak:
96
96
97
97
>>> Post.objects.filter(author=me)
98
-
[<Post: Mój pierwszy wpis>, <Post: Kolejny tytuł wpisu>, <Post: Przykładowy tytuł>, <Post: Wpis numer 2>, <Post: Mój trzeci post!>, <Post: Czwarty tytuł>]
98
+
<QuerySet [<Post: Mój pierwszy wpis>, <Post: Kolejny tytuł wpisu>, <Post: Przykładowy tytuł>, <Post: Wpis numer 2>, <Post: Mój trzeci post!>, <Post: Czwarty tytuł>]>
99
99
100
100
101
101
A gdybyśmy chciały wyświetlić wszystkie wpisy zawierające słowo 'title' w polu `tytuł`?
[<Post: Kolejny tytuł wpisu>, <Post: Przykładowy tytuł>, <Post: Czwarty tytuł>]
104
+
<QuerySet [<Post: Kolejny tytuł wpisu>, <Post: Przykładowy tytuł>, <Post: Czwarty tytuł>]>
105
105
106
106
107
107
> **Uwaga:** Pomiędzy `title` a `contains` znajdują się dwa znaki podkreślenia (`_`). ORM w Django używa takiej składni, aby oddzielić nazwy pól ("title") od operacji lub filtrów ("contains"). Jeśli użyjesz tylko jednego, zobaczysz błąd o treści "FieldError: Cannot resolve keyword title_contains".
@@ -127,7 +127,7 @@ A następnie opublikuj go za pomocą metody `publish`!
127
127
Teraz spróbujmy jeszcze raz wyświetlić listę opublikowanych wpisów (wciśnij trzykrotnie klawisz ze strzałką do góry, a następnie zatwierdź klawiszem `Enter`):
Copy file name to clipboardExpand all lines: pl/django_templates/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Spróbuj tak zrobić w szablonie` blog/templates/blog/post_list.html`. Zastąp w
26
26
27
27
Jak widzisz, dostaliśmy tylko tyle:
28
28
29
-
[<Post: My second post>, <Post: My first post>]
29
+
<QuerySet [<Post: My second post>, <Post: My first post>]>
30
30
31
31
32
32
Oznacza to tyle, że Django rozumie to jako listę obiektów. Pamiętasz z rozdziału **Wprowadzenie do Pythona**, jak możemy wyświetlić zawartość listy? Tak, za pomocą pętli for! W szablonie Django używamy ich w ten sposób:
0 commit comments