BBS - 预备知识

一、中介模型

四个项目:
苑昊

博客(BBS) (7-8)

CRM
    1.权限组件 (3)
    2.start组件 -- admin (5)
        1.使用
        2.源码 django 源码 (面向对象)
            以源码为导师
            使用python最顶头的人写出来的
        3.开发类似于源码的组件
        4.面向对象。。。优点。。。
    3.crm (4)

路飞学城
    1.vue (3)
    2.rest-framework (4)
    3.路飞学诚

爬虫
linux
flask

-------------------------------------------------
Book():
    title =
    publish = models.ForeignKey(to='Publish',to_field='id')
    authors = models.manytomany(to='author')

Publish():
    name=
    email=

Author():
    name=

book author
    id  book_id  author_id
     1       1     1

class book2author():
    id=
    book=models.ForeignKey('Book')
    author=models.ForeignKey('Author')
    xxx=models...

book2author
    id  book_id  author_id
     1       1     1

     book_obj = Book.object.filter(pk=1).first()
     book_obj.authors.all()
     book_obj.authors.add(1,2)
     book_obj.authors.set([1,2]) 刷新在插入
                      remove  解除
                      clear   全解除

     如果没有  // authors = models.manytomany(to='author')
        Book2author.object.create(book_id=1,author_id=2)
        意味着 跨表查询没有了  正向查询按字段 反向查询按表名
        那如果用字段authors = models.manytomany(to='author'),但是第三张表用自己的!
             authors = models.manytomany(to='author',through="Book2Author")...通过through
             以后跨表查询就走的是自己建的表,(中介模型)自己建的表(Book2Author叫中介模型)可进行扩展

中介模型:第三张表 可以create 可不可以add? 不可以!!
    Book2author.object.create(book_id=1,author_id=2)
    book_obj.authors.add(1,2) 这个方法就不能使用了!!否则就会报错 add  set  remove  clear  都不能用了
笔记
中介模型:
只针对 多对多
authors = models.manytomany(to='author')
book_obj.authors.add(1,2)
authors = models.manytomany(to='author',through="Book2Author") # (好处,可扩展)
#(add set remove clear 都不能用了!!)
# 不能使用接口函数!
Book2author.object.create(book_id=1,author_id=2,... )
class Book2Author():
id = ...
book = models.Foreignkey()
author = models.ForeighKey()
xxx = ... # 有可能有多个字段。。扩展

二、简介

博客系统(cnblog) https://www.cnblogs.com/
预备知识:
1.django ORM (object relation mapping 对象关系映射) 表 = 类 对象 = 记录
跨表查询 分组查询 annotate() 聚合查询 aggregate(*args, **kwargs)
2.bootstrap
3.Ajax (jquery javascript) --- javascript 去写ajax 去写写
登录注册 点赞评论
用框架 底层要会!
4.用户认证系统!
auth user session 考虑的太多 会报异常!!所以用auth user

实现功能:
1.基于Ajax和用户认证实现登录验证!
--- 验证码 图片 滑动(插件)
登录 注册 Ajax

2.基于Ajax和form组件实现注册功能!

3.系统首页的布局
https://www.cnblogs.com/

表关系 第一步:
文章表: 表头 内容,发布时间
用户表: 一对多

4.个人站点页面设计
https://www.cnblogs.com/wupeiqi
https://www.cnblogs.com/linhaifeng

标签 分类 归档(发布日期 group by)
分类表:一对多 和文章表
标签表:多对多 和文章表

5.文章详细页面
模板继承
文章表 content内容非常多,分成两张表,否则会每次都查所有的字段;
Artical
id
title ...
desc ...
create_time ...
ad_id = models.OneToOne() 1 / 5
ArticalDetail:
id
content ...
一对一

6.基于Ajax实现文章点赞与踩灭
描述行为的就是数据;
ArticalUpDown
id
user_id
artical_id
is_up true false
( user_id artical_id 联合唯一 unqiue_together )
ArticalUpDown.object.create()

7.基于Ajax实现评论框
Comment:
id
user_id
artical_id
create_time
content

对文章的评论和对评论的评论
评论树:
111
444
555
666
222
333
评论楼:
直接按时间下来的

user
id name
1 alex
2 egon

id user_id artical_id create_time content p_id(记录父评论)
1 1 2 2012 111 None
2 2 2 2012 222 None
3 3 2 2012 333 None
4 4 2 2012 444 1
5 5 2 2012 555 4
6 6 2 2012 666 1

create Comment():
id = ...
user = models.ForeignKey('User')
artical = models.ForeignKey('Artical')
create_time =
content = ...
pid = models.ForeignKey("selef",null=true,default=None) # 表的自关联

8.kindeditor 文本编辑器
防止跨域,安全攻击!发文章 有些<js>恶意攻击
思路:1.转义,对文章过滤,<script></script>
beautitulSoup 模块

三、xxx




猜你喜欢

转载自www.cnblogs.com/alice-bj/p/9118669.html
bbs