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

相关推荐
木头左2 小时前
逻辑回归的Python实现与优化
python·算法·逻辑回归
quant_19863 小时前
R语言如何接入实时行情接口
开发语言·经验分享·笔记·python·websocket·金融·r语言
失败又激情的man8 小时前
python之requests库解析
开发语言·爬虫·python
打酱油的;8 小时前
爬虫-request处理get
爬虫·python·django
用什么都重名10 小时前
MinerU:高效智能PDF文档解析工具完全指南
人工智能·python·pdf·mineru·makedown
倔强青铜三10 小时前
苦练Python第4天:Python变量与数据类型入门
前端·后端·python
这我可不懂10 小时前
Python 项目快速部署到 Linux 服务器基础教程
linux·服务器·python
倔强青铜三10 小时前
苦练Python第3天:Hello, World! + input()
前端·后端·python
小白学大数据10 小时前
Python爬取闲鱼价格趋势并可视化分析
开发语言·python
七月初七淮水竹亭~11 小时前
Pycharm 报错 Environment location directory is not empty 如何解决
ide·python·pycharm