Django 5 By Example Study Day 9, p651-p678 Summary, 28 pages total.
I. Technical summary
()
(1)aggregate:ad-("to") + gregare("to collection into a flock(swarm), to gather")
Because ad is followed by gregate, for the sake of pronunciation, ad has evolved into ag. aggregate originally means: vt. to combine into a single group (polymerization, multiple things > single group).
typical example:The butterflies aggregate in dense groups(Butterflies gather together).
(2) annotate inside the database
aggregate()The meaning of the term inside the database is:aggregate refer to the process of summarizing or combining data from multiple row into a single result(multiple row > single result)。for example:SUM(),AVG(),COUNT(),MAX(),MIN()are called aggregate functions。
Example:
SELECT AVG(price) FROM book;
(3) Aggregate in Django
Example:
# Average price across all books, provide default to be returned instead
# of None if no books exist.
>>> from import Avg
>>> (Avg("price", default=0))
{'price__avg': 34.35}
()
(1)annotate:ad-("to") + notare("to mark, to note")
Because ad is followed by notare, for the convenience of pronunciation, ad evolved into an. The original meaning of annotate is: to add marks or notes to explain on sth (to ..... to make notes, to ...... add comments).
(2) annotate inside the database
annotate()The meaning of the term inside the database is:annotate refers to adding supplementary information to queries or can help provide context, make data more understandable, or enhance the the functionality of queries or results.
Example:
COMMENT ON COLUMN IS 'Employee annual salary';
(3) Django inside the annotate
The annotate() function inside Django does the following: Annotates each object in the QuerySet with the provided list of query expressions (using the provided query expressions to annotate each object in the QuerySet). Annotates each object in the QuerySet with the provided list of query expressions. The result of adding an annotation is one more field for each objec in the QuerySet).
Example:
# Build an annotated queryset
>>> from import Count
>>> q = (Count("authors"))
# Interrogate the first object in the queryset
>>> q[0]
<Book: The Definitive Guide to Django>
>>> q[0].authors__count
2
# Interrogate the second object in the queryset
>>> q[1]
<Book: Practical Django Projects>
>>> q[1].authors__count
1
serializer
(1) Definitions
p648, Serializer: Provides serialization for normal Python class instances。
(2) Classification
SerializerIt is further subdivided intoSerializer, ModelSerializer, HyperlinkedModelSerializer.
(3)Field
IntegerField(),SerializerMethodField(),StringRelatedField()。
(4)nested serializer
The nested serializer can be used as an alternative to StringRelatedField().
tab window (in a web browser etc)
DRF uses PageNumberPagination for paging.
authentication
(1)BasicAuthentication
(2)TokenAuthentication
(3)SessionAuthentication
(4)RemoteUserAuthentication
and mentioned the certification, I'm going to faint, almost every project to engage in a certification, can be abstracted out to do a whole introduction not? After all, this piece of certification in the actual project will not change so much, there is really no need to spend so many chapters to introduce certification.
II. English summary (vocabulary: 0)
None.
III. Other
(1)json_pp
curl http://127.0.0.1:8000/api/subjects/ | json_pp
I do not know why, I feel that foreign authors especially like to use curl, I last saw or curl combined with the use of jq, this time it is curl combined with the use of json_pp, in the postman and the command line between the repeated jump. Maybe it's too much trouble for postman to input the address?
Refreshed the meaning and usage of functions such as aggregate(), annotate(), etc. I learned it too roughly before, not detailed enough, and slowly forgot its usage.
chapter 15 brief comment: online learning platform as an example, introduces how to integrate django-rest-framework in the Django project. this learning platform is introduced in the first few chapters, I feel that the layout is very unreasonable, if it is a project, it is best to use a whole chapter to introduce the better. At the same time since all use django-rest-framework, why not a whole front-end framework?
IV. References
1. Programming
(1) Antonio Melé,《Django 5 By Example》:/subject/37007362/
2. English
(1) Etymology Dictionary:
(2) Cambridge Dictionary:
Welcome to search and follow: programmers (a_codists)