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

相关推荐
Joker Zxc19 分钟前
【Django】多个APP设置独立的URL
python·django·django的url
圣道寺28 分钟前
审计文件标识作为水印打印在pdf页面边角
java·前端·python·pdf·学习方法
荣--35 分钟前
Windows 快速启动器
python·alias
Edward-tan1 小时前
【玩转全栈】----Django模板的继承
后端·python·django
安替-AnTi1 小时前
淘宝关键词页面爬取&绘图进行数据分析
python·信息可视化·关键词·爬取·tb
Q_27437851091 小时前
django应急物资管理系统
后端·python·django
程序员一诺1 小时前
【Python使用】嘿马头条项目从到完整开发教程第10篇:APScheduler定时任务,1. 什么是RPC【附代码文档】
后端·python
喜-喜2 小时前
Python学习之旅:入门阶段(七)数据结构
数据结构·python·学习
C7211BA2 小时前
UMAP(Uniform Manifold Approximation and Projection)算法
python·算法·信息可视化
莲动渔舟2 小时前
PyTest自学 - pytest的各种执行方式
开发语言·python·pytest