-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: flashdagger <flashdagger@googlemail.com>
- Loading branch information
1 parent
39b2c59
commit 5481e31
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
======== | ||
Tutorial | ||
======== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Objects can be lazy | ||
=================== | ||
|
||
| Consider the following example: | ||
| We enable logging and create a ticket object | ||
by its id. Then we print the ticket id, number and title. | ||
.. code-block:: python | ||
import logging | ||
logging.basicConfig(level=logging.INFO) | ||
ticket = client.tickets(1) | ||
print(f"ticket id: {ticket.id}") | ||
print(f"ticket number: #{ticket.number}") | ||
print(f"ticket title: {ticket.title!r}") | ||
# ticket id: 1 | ||
# INFO:zammadoo:HTTP:GET https://localhost/api/v1/tickets/1 | ||
# ticket number: #67001 | ||
# ticket title: 'Welcome to Zammad!' | ||
What happened? Before printing the ticket number the client made a server request | ||
to fetch the ticket data. This means if we instantiate an object it only contains | ||
its id. The first time we get an attribute or perform a method which requires attributes | ||
the data is queried from the server. This is called lazy object initialization and applies | ||
to most resources. |