《Django 5 By Example》阅读笔记:p521-p542

《Django 5 By Example》学习第 18 天,p521-p542 总结,总计 22 页。

一、技术总结

1.django-parler

django-parler 用于 model 的 translate。这里要注意下,使用 django-parler 之后会生成新的表,对原来的表数据有影响。本人未在实际项目中做过国际化开发,但个人觉得这种做法不好。

2.项目:e-learning

(1)subject & course

复制代码
from django.db import models
from django.contrib.auth.models import User


# Create your models here.

class Subject(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField(max_length=200, unique=True)

    class Meta:
        ordering = ['title']

    def __str__(self):
        return self.title


class Course(models.Model):
    owner = models.ForeignKey(User, related_name='courses_created', on_delete=models.CASCADE)
    subject = models.ForeignKey(Subject, on_delete=models.CASCADE, related_name='courses')
    title = models.CharField(max_length=200)
    slug = models.SlugField(max_length=200, unique=True)
    overview = models.TextField()
    created = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['created']

    def __str__(self):
        return self.title


class Module(models.Model):
    course = models.ForeignKey(
        Course, related_name='modules', on_delete=models.CASCADE
    )
    title = models.CharField(max_length=200)
    description = models.TextField(blank=True)

    def __str__(self):
        return self.title

虽然作者使用了 ForeignKey() 定义 subject 和 course 的关系,但是我觉得ManyToManyField() 更好一些,因为一门课程可以从属于多个专业。

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

1.accommodate

p537, You will learn how to create flexible data models that accommodate diverse data types and discover how to implement custom model functionalities that you can apply to your future Django projects.

(1)accommodate: ad-("to") + commodare("make fit")

vt. fit one thing to another(适应)。

三、其它

1.再次体会作者的"废话文学"

In the previous chapter, you learned the basics of the internationalization and localization of Django projects, adapting your project to meet the local formats and languages for your users.

In this chapter, you will start a new Django project that will consist of an e-learning platform with your own content management system (CMS). Online learning platforms are a great example of applications that require tools for advanced content handling. You will learn how to create flexible data models that accommodate diverse data types and discover how to implement custom model functionalities that you can apply to your future Django projects.

In this chapter, you will learn how to:

•Create models for the CMS

•Create fixtures for your models and apply them

•Use model inheritance to create data models for polymorphic content

•Create custom model fields

•Order course contents and modules

•Build authentication views for the CMS

这是第 12 章的开篇内容,我们来梳理一下:

第一段介绍了前面一章(第 11 章)的内容,然后呢?跟后一章有什么关系吗?这个过渡咱能不能衔接一下?

第二段介绍了需要学习的内容(在线学习平台+CMS(内容管理系统))。Online learning platforms are a great example of applications that require tools for advanced content handling.------great, advanced 这些形容词非常模糊,完全没有必要,什么叫great example?前面 11 章的 example 是不是 great example? 什么叫 advanced content handling?

总之概括下来就是说着说了很多东西,但是又好像什么都没说。

2.再谈书名《Django 5 By Example》

看到第 12 章我悟了,这本书重点在于"如何使用 Django 实现 Example",而不是"Django技术详解"。

四、参考资料

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)

相关推荐
天天爱吃肉821836 分钟前
ZigBee通信技术全解析:从协议栈到底层实现,全方位解读物联网核心无线技术
python·嵌入式硬件·物联网·servlet
Allen_LVyingbo1 小时前
Python常用医疗AI库以及案例解析(2025年版、上)
开发语言·人工智能·python·学习·健康医疗
智能砖头1 小时前
LangChain 与 LlamaIndex 深度对比与选型指南
人工智能·python
风逸hhh3 小时前
python打卡day58@浙大疏锦行
开发语言·python
烛阴4 小时前
一文搞懂 Python 闭包:让你的代码瞬间“高级”起来!
前端·python
JosieBook4 小时前
【Java编程动手学】Java中的数组与集合
java·开发语言·python
Gyoku Mint5 小时前
深度学习×第4卷:Pytorch实战——她第一次用张量去拟合你的轨迹
人工智能·pytorch·python·深度学习·神经网络·算法·聚类
郭庆汝10 小时前
pytorch、torchvision与python版本对应关系
人工智能·pytorch·python
思则变13 小时前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
漫谈网络14 小时前
WebSocket 在前后端的完整使用流程
javascript·python·websocket