《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)

相关推荐
ኈ ቼ ዽ36 分钟前
OpenCV 图片矫正
人工智能·python·opencv·计算机视觉
xing251636 分钟前
python脚本:向kafka数据库中插入测试数据
数据库·python·kafka
言之。2 小时前
[Python] 操作redis使用pipeline保证原子性
redis·python
Taichi呀3 小时前
Python字符串常用操作
开发语言·python
不知名网友小H4 小时前
【h5py】 提取mat文件中的HDF5格式的数据
人工智能·python
老大白菜4 小时前
基于Go和Python的高效Web开发实战解析
前端·python·golang
小张Tt6 小时前
基于python快速部署属于你自己的页面智能助手
人工智能·python
我要学编程(ಥ_ಥ)6 小时前
初始Python篇(11)—— 面向对象三大特征
开发语言·python
Ws_6 小时前
pytest 的简单介绍
python·pytest
数据分析螺丝钉6 小时前
力扣250题:计算同值子树数量(Count Univalue Subtrees)
经验分享·python·算法·leetcode·面试