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

相关推荐
0wioiw05 分钟前
Python基础(Flask①)
后端·python·flask
飞翔的佩奇26 分钟前
【完整源码+数据集+部署教程】食品分类与实例分割系统源码和数据集:改进yolo11-AggregatedAttention
python·yolo·计算机视觉·数据集·yolo11·食品分类与实例分割
OperateCode42 分钟前
AutoVideoMerge:让二刷更沉浸的自动化视频处理脚本工具
python·opencv·ffmpeg
蔡俊锋42 分钟前
Javar如何用RabbitMQ订单超时处理
java·python·rabbitmq·ruby
跟橙姐学代码1 小时前
学Python别死记硬背,这份“编程生活化笔记”让你少走三年弯路
前端·python
站大爷IP2 小时前
Python与MySQL:从基础操作到实战技巧的完整指南
python
老歌老听老掉牙2 小时前
SymPy 矩阵到 NumPy 数组的全面转换指南
python·线性代数·矩阵·numpy·sympy
站大爷IP2 小时前
Python条件判断:从基础到进阶的实用指南
python
赛博郎中2 小时前
pygame小游戏飞机大战_8继承精灵玩家优化
python·pygame
William一直在路上2 小时前
Python数据类型转换详解:从基础到实践
开发语言·python