《Django 5 By Example》学习第11天,p237-p338总结,总计102页。

一、技术总结

1.follow system(关注功能)

表之间的关系有三种:OneToOneField,many-to-one(使用Foreignkey()),ManyToManyField。有时候为了更好的描述对象之间的关系,需要多创建一张中间表:Creating an intermediate model is necessary when you want to store additional information on the relationship, for example, the date when the relationship was created, or a field that describes the nature of the relationship。

例如关注功能:

class Contact(models.Model):

    user_from = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='rel_from_set')

    user_to = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='rel_to_set')

    created = models.DateTimeField(auto_now_add=True)

    class Meta:

        indexes = [

            models.Index(fields=['-created']),

         ]

        ordering = ['-created']

    def __str__(self):

        return f'{self.user_from.username} follows {self.user_to.name}'

2.monkey patch

p289, You use the add_to_class() method of Django models to monkey patch the User model。monkey patch的意思是:Monkey patch is a technique used to dynamically update the code at runtime without altering the source code。示例:

# monkey patch 示例

user_model = get_user_model()

user_model.add_to_class(

    'following',

    models.ManyToManyField('self', through=Contact, symmetrical=False, related_name='followers')

)

注:尽量少用monkey patch。

3.activity stream(活动流)功能

4.contenttypes

p300, contenttypes 的作用:This application can track all models installed in your project and provides a generic interface to interact with your models.

5.denormalization(反规范化)

p315, Denormalization is making data redundant in such a way that it optimizes read performance. For example, you might be copying related data to an object to avoid expensive read queries to the database when retrieving the related data.

6.signal

7.django-debug-toolbar

用于完善debug功能,在界面通过toolbar显示一些统计信息。个人觉得在实际开发中可有可无。

8.使用redi做缓存

使用的 package 名称也叫redis。在实际业务也中经常使用,但是不复杂,掌握常用的方法即可。

二、英语总结(生词:2)

1.thewart

p292. Usernames, unlike sequential IDs, thwart enumeration attacks by obscuring your data structure.

vt. to stop sth from happing.

2.every once in a while

p327, Redis stores everything in memory, but the data can be persisted by dumping the dataset to disk every once in a while, or by adding each command to a log.

idiom. sometimes, but not regularly. 也写作 every so often。

三、其它

chapter 07 简评:4-7 章是一个完整的项目(bookmarks),建议从第 4 章按顺序阅读到第 7 章,不要跳过某个章节,因为作者的代码是连续,跳过之后项目可能无法运行。

Pycharm(2024.3 Professional Edition) :Settings > Build, Execution, Deployment > Python Debugger新增了一个功能 "Run debugger in server mode",然后 Pycharm 默认是勾选的,导致我在 WSL 使用 debug 启动后一直无法访问。忍了那么久终于可以debug了,气 die! Pycharm,你再这样我明年就不续费了。

四、参考资料

1. 编程

(1) Antonio Melé,《Django 5 By Example》:https://book.douban.com/subject/37007362/

2. 英语

(1) Etymology Dictionary:https://www.etymonline.com

(2) Cambridge Dictionary:https://dictionary.cambridge.org

欢迎搜索及关注:编程人(a_codists)

《Django 5 By Example》阅读笔记:p237-p338的更多相关文章

  1. django1.8.3搭建博客——2 django web 开发指南阅读笔记

    一.    django框架 1 .http封装web服务的整个过程.由请求(request)和响应(response)两部分组成. 请求的内容为URL (指向文档的路径). 响应主要为正文(body ...

  2. 《Java编程思想》阅读笔记二

    Java编程思想 这是一个通过对<Java编程思想>(Think in java)进行阅读同时对java内容查漏补缺的系列.一些基础的知识不会被罗列出来,这里只会列出一些程序员经常会忽略或 ...

  3. 阅读笔记 1 火球 UML大战需求分析

    伴随着七天国庆的结束,紧张的学习生活也开始了,首先声明,阅读笔记随着我不断地阅读进度会慢慢更新,而不是一次性的写完,所以会重复的编辑.对于我选的这本   <火球 UML大战需求分析>,首先 ...

  4. [阅读笔记]Software optimization resources

    http://www.agner.org/optimize/#manuals 阅读笔记Optimizing software in C++   7. The efficiency of differe ...

  5. 《uml大战需求分析》阅读笔记05

    <uml大战需求分析>阅读笔记05 这次我主要阅读了这本书的第九十章,通过看这章的知识了解了不少的知识开发某系统的重要前提是:这个系统有谁在用?这些人通过这个系统能做什么事? 一般搞清楚这 ...

  6. <<UML大战需求分析>>阅读笔记(2)

    <<UML大战需求分析>>阅读笔记(2)> 此次读了uml大战需求分析的第三四章,我发现这本书讲的特别的好,由于这学期正在学习设计模式这本书,这本书就讲究对uml图的利用 ...

  7. uml大战需求分析阅读笔记01

    <<UML大战需求分析>>阅读笔记(1) 刚读了uml大战需求分析的第一二章,读了这些内容之后,令我深有感触.以前学习uml这门课的时候,并没有好好学,那时我认为这门课并没有什 ...

  8. Hadoop阅读笔记(七)——代理模式

    关于Hadoop已经小记了六篇,<Hadoop实战>也已经翻完7章.仔细想想,这么好的一个框架,不能只是流于应用层面,跑跑数据排序.单表链接等,想得其精髓,还需深入内部. 按照<Ha ...

  9. Hadoop阅读笔记(六)——洞悉Hadoop序列化机制Writable

    酒,是个好东西,前提要适量.今天参加了公司的年会,主题就是吃.喝.吹,除了那些天生话唠外,大部分人需要加点酒来作催化剂,让一个平时沉默寡言的码农也能成为一个喷子!在大家推杯换盏之际,难免一些画面浮现脑 ...

  10. Hadoop阅读笔记(五)——重返Hadoop目录结构

    常言道:男人是视觉动物.我觉得不完全对,我的理解是范围再扩大点,不管男人女人都是视觉动物.某些场合(比如面试.初次见面等),别人没有那么多的闲暇时间听你诉说过往以塑立一个关于你的完整模型.所以,第一眼 ...

随机推荐

  1. 【YashanDB知识库】ycm托管数据库时报错OM host ip:127.0.0.1 is not support join to YCM

    问题现象 托管数据库时检查报错OM的IP是127.0.0.1,不支持托管到YCM OM 问题的风险及影响 导致数据库无法托管监控 问题影响的版本 问题发生原因 安装数据库时修改了OM的监听ip为127 ...

  2. 声明式 Shadow DOM:简化 Web 组件开发的新工具

    在现代 Web 开发中,Web 组件已经成为创建模块化.可复用 UI 组件的标准工具.而 Shadow DOM 是 Web 组件技术的核心部分,它允许开发人员封装组件的内部结构和样式,避免组件的样式和 ...

  3. CSS – 实战 Font

    前言 这篇想整理一下在网页开发中, 字体是如果被处理的. 先看完: 平面设计 – 字体 CSS – Font / Text 属性 CSS – Font Family CSS – word-break, ...

  4. CSS – 网页设计 Web Design

    前言 Web Design 很广很深. 我记得许多年前第一次想介入设计工作 (我是后端工程师), 我就上网搜索了一下. 就看见了乔布斯著名的一句话: Design is not just what i ...

  5. idea运行java项目main方法报build failure错误的解决方法

    当在使用 IntelliJ IDEA 运行 Java 项目的 main 方法时遇到 "Build Failure" 错误,这通常意味着在项目的构建过程中遇到了问题.解决这类问题通常 ...

  6. Element PRO 破解版 3.18.1版插件

    百度网盘提取 链接:https://pan.baidu.com/s/1KKOm7O1ghhIoYNiQPdzG_Q 提取码:1234

  7. KubeSphere 社区双周报 | KubeKey v3.0.7 发布 | 2023-02-03

    KubeSphere 从诞生的第一天起便秉持着开源.开放的理念,并且以社区的方式成长,如今 KubeSphere 已经成为全球最受欢迎的开源容器平台之一.这些都离不开社区小伙伴的共同努力,你们为 Ku ...

  8. .NET使用OllamaSharp实现大模型推理对话的简单演示

      前提条件:请确保你本地已经安装了ollama以及有关本地离线模型.或者已有远程模型环境等.如果没有,请自行部署.如果需要帮助,可以文末获取联系方式咨询.由于部署离线大模型过于简单,在线资料也很多, ...

  9. Derivative norm vector repect to time 《PBM by Pixar》 Appendix D.2 code

    目录 1 Derivative normal vector repect to time 1.1 Derivative vector norm repect to time X Ref Vector ...

  10. 马斯克对于CEO职能,发挥人才天赋,激励人才的想法

    Time Interview with Elon Musk, 29 September 2011. Content 1 Have people do be focused on doing usefu ...