SlideShare a Scribd company logo
DJANGO 實戰系列列⼯工作坊
⾃⼰的購物網站⾃⼰做
Michelle @flywindy 2016.11.29
活動介紹
請問你哪位?
組織介紹 -
➤ Taipei.py
➤ 台灣最⼤的 python user
group
➤ PyCon Taiwan
➤ Python Web Meetup
➤ Django Girls Taipei
➤ 2014~
➤ 初學者⼯作坊(⼀⽇)
➤ Django 新⼿村
為什什麼要辦這個?
活動⽬目的
➤ 社群的⽬的︖
➤ 交流︖同好會︖學習︖
➤ Python Web Meetup
➤ 讀書會
➤ 分享會
➤ 新⼿村 (2015.7~)
➤ 系列課程 v.s. 單⼀課程
➤ 實戰⼯作坊 v.s. 新⼿村
我適合參參加嗎?
不限性別、年齡、職業
➤ 完成 Django Girls Taipei 學習指南(安裝好 Python 3.5)

那...今天要做什什麼?
活動流程
➤ 課程時間
➤ 交流時間
➤ 實作時間
➤ 新⼿:先照著做⼀遍
➤ 非新⼿:實作⾃⼰的網站
➤ ⽼⼿:幫忙同組的朋友
➤ 分享時間
➤ 開放報名閃電秀
➤ 每組⼀位⼼得分享
購物網站
以⼆⼿書網站為例
⾸首⾴頁
➤ 商品列表
➤ 最新商品
➤ 熱⾨商品(排⾏榜)
➤ 分⾴
➤ 商品分類
➤ 搜尋列
商品⾴頁⾯面
➤ 顯⽰商品
➤ 商品細節
➤ 圖⽚集
➤ 加入購物⾞
➤ 相關商品(推薦系統)
會員系統
➤ 會員註冊/登入
➤ Facebook 註冊/登入
➤ 會員管理
➤ 修改會員資料
➤ 訂單管理
➤ 訂單列表
購物⾞車車
➤ 購物商品列表
➤ 修改數量
➤ 計算售價
➤ 結帳
後台管理理
➤ 會員管理
➤ 商品上架管理
➤ 訂單管理
➤ 出貨管理
課程規劃
➤ 第⼀堂 - 商品管理:11/29(⼆)
➤ 第⼆堂 - 版本管理:12/13(⼆)
➤ 第三堂 - 商品呈現:12/27(⼆)
➤ 第四堂 - 雲端部署:1/10(⼆)
➤ 第五堂 - 前端美化:1/24(⼆)
➤ 第六堂 - 會員管理:2/7(⼆)
➤ 後台系統、購物⾞、訂單管理、搜尋商品、推薦商品......
商品管理理
第⼀堂
“https://github.com/djangogirlstaipei/
eshop
-購物網站實作範例
GETTING STARTED
➤ venv
➤ install django (1.10.3)
➤ $ python -m django —version
➤ $ which django-admin.py
➤ startproject
➤ ex: bookshop
➤ startapp
➤ ex: books
MODELS
➤ Book
➤ name
➤ description
➤ original_price
➤ price
➤ author
➤ translator
➤ publisher
➤ isbn
➤ language
MODELS
➤ Book
➤ status
➤ created
➤ updated
➤ published
➤ category
➤ tags
MODEL FIELD
➤ Field types
➤ CharField v.s. TextField
➤ DateTimeField (ex: created, updated, published)
➤ auto_now v.s. auto_now_add
➤ PositiveIntegerField (ex: price)
➤ PositiveSmallIntegerField (ex: status)
➤ EmailField / URLField
➤ CharField
➤ SlugField
➤ FileField / ImageField
MODEL FIELD
➤ Field options
➤ null=True v.s. blank=True
➤ CharField & TextField only need to use blank=True
➤ default
➤ choices
➤ ex: status
➤ help_text
➤ unique
➤ db_index
➤ db_column
MODELS
➤ Relationship fields
➤ ForeignKey
➤ Many-to-one relationships
➤ ManyToManyField
➤ OneToOneField
Book
Category Tag
1
m m
n
MIGRATIONS
➤ makemigrations & migrate
➤ sqlmigrate, which displays the SQL statements for a
migration.
➤ ex: python manage.py sqlmigrate books 0001
➤ showmigrations, which lists a project’s migrations and their
status.
➤ New in 1.10
➤ python manage.py migrate —list (before 1.10)
ADMIN
➤ createsuperuser
➤ Password - It must contain at least 8 characters. (1.10)
➤ admin.py
➤ @admin.register(Book)
➤ admin.site.register(Book)
➤ __str__ method
ADMIN 中⽂文化
英⽂不好,後台可以是中⽂的嗎︖
ADMIN 中⽂文化 - PART I
➤ settings.py
➤ LANGUAGE_CODE = 'zh-hant'
Django 實戰 - 自己的購物網站自己做
MODEL META
➤ Model Meta options
➤ db_table
➤ default: books_book
➤ ordering
➤ ex: ordering = [‘-published']
➤ unique_together
➤ ex: unique_together = (("name", "author"),)
➤ ManyToManyField cannot be included in
unique_together
ADMIN 中⽂文化 - PART II
➤ Model Meta options
➤ verbose_name & verbose_name_plural
Django 實戰 - 自己的購物網站自己做
ADMIN 中⽂文化 - PART III
➤ books/apps.py
➤ books/__init__.py
Django 實戰 - 自己的購物網站自己做
ADMIN 中⽂文化 - PART IV
➤ Model Field options
➤ verbose_name
VIEWS
➤ Templates
➤ settings.py
➤ home.html
➤ views.py
➤ home function
➤ urls.py
NEXT
第⼆堂 - 版本管理
Ad

More Related Content

What's hot (8)

從線上售票看作業系統設計議題
從線上售票看作業系統設計議題從線上售票看作業系統設計議題
從線上售票看作業系統設計議題
National Cheng Kung University
 
TECHTALK 20210727 モニタリングツールでQlik Senseの 運用環境を最適化
TECHTALK 20210727 モニタリングツールでQlik Senseの 運用環境を最適化 TECHTALK 20210727 モニタリングツールでQlik Senseの 運用環境を最適化
TECHTALK 20210727 モニタリングツールでQlik Senseの 運用環境を最適化
QlikPresalesJapan
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
All Things Open
 
自動化ハンズオン
自動化ハンズオン自動化ハンズオン
自動化ハンズオン
VirtualTech Japan Inc.
 
ファントム異常を排除する高速なトランザクション処理向けインデックス
ファントム異常を排除する高速なトランザクション処理向けインデックスファントム異常を排除する高速なトランザクション処理向けインデックス
ファントム異常を排除する高速なトランザクション処理向けインデックス
Sho Nakazono
 
Java 101
Java 101Java 101
Java 101
Manuela Grindei
 
ανθρωπάκι αφήγησης
ανθρωπάκι αφήγησηςανθρωπάκι αφήγησης
ανθρωπάκι αφήγησης
Ioanna Chats
 
GitLab から GitLab に移行したときの思い出
GitLab から GitLab に移行したときの思い出GitLab から GitLab に移行したときの思い出
GitLab から GitLab に移行したときの思い出
富士通クラウドテクノロジーズ株式会社
 
TECHTALK 20210727 モニタリングツールでQlik Senseの 運用環境を最適化
TECHTALK 20210727 モニタリングツールでQlik Senseの 運用環境を最適化 TECHTALK 20210727 モニタリングツールでQlik Senseの 運用環境を最適化
TECHTALK 20210727 モニタリングツールでQlik Senseの 運用環境を最適化
QlikPresalesJapan
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
All Things Open
 
ファントム異常を排除する高速なトランザクション処理向けインデックス
ファントム異常を排除する高速なトランザクション処理向けインデックスファントム異常を排除する高速なトランザクション処理向けインデックス
ファントム異常を排除する高速なトランザクション処理向けインデックス
Sho Nakazono
 
ανθρωπάκι αφήγησης
ανθρωπάκι αφήγησηςανθρωπάκι αφήγησης
ανθρωπάκι αφήγησης
Ioanna Chats
 

More from flywindy (8)

Ready Programmer One
Ready Programmer OneReady Programmer One
Ready Programmer One
flywindy
 
Django workshop homework 3
Django workshop homework 3Django workshop homework 3
Django workshop homework 3
flywindy
 
那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子
flywindy
 
Two scoops of Django - Deployment
Two scoops of Django - DeploymentTwo scoops of Django - Deployment
Two scoops of Django - Deployment
flywindy
 
Django best practices for logging and signals
Django best practices for logging and signals Django best practices for logging and signals
Django best practices for logging and signals
flywindy
 
Two scoops of django 1.6 - Ch7, Ch8
Two scoops of django 1.6  - Ch7, Ch8Two scoops of django 1.6  - Ch7, Ch8
Two scoops of django 1.6 - Ch7, Ch8
flywindy
 
Working with the django admin
Working with the django admin Working with the django admin
Working with the django admin
flywindy
 
Two scoops of django Introduction
Two scoops of django IntroductionTwo scoops of django Introduction
Two scoops of django Introduction
flywindy
 
Ready Programmer One
Ready Programmer OneReady Programmer One
Ready Programmer One
flywindy
 
Django workshop homework 3
Django workshop homework 3Django workshop homework 3
Django workshop homework 3
flywindy
 
那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子那些年,我用 Django Admin 接的案子
那些年,我用 Django Admin 接的案子
flywindy
 
Two scoops of Django - Deployment
Two scoops of Django - DeploymentTwo scoops of Django - Deployment
Two scoops of Django - Deployment
flywindy
 
Django best practices for logging and signals
Django best practices for logging and signals Django best practices for logging and signals
Django best practices for logging and signals
flywindy
 
Two scoops of django 1.6 - Ch7, Ch8
Two scoops of django 1.6  - Ch7, Ch8Two scoops of django 1.6  - Ch7, Ch8
Two scoops of django 1.6 - Ch7, Ch8
flywindy
 
Working with the django admin
Working with the django admin Working with the django admin
Working with the django admin
flywindy
 
Two scoops of django Introduction
Two scoops of django IntroductionTwo scoops of django Introduction
Two scoops of django Introduction
flywindy
 
Ad

Django 實戰 - 自己的購物網站自己做