d5

s7day132

內容回顧:

1.rest組件python

  • 版本. 認證 . 權限 .組件
  • 視圖
  • 序列化

2.跨域數據庫

  • jsonp,實現原理
  • cors
    • 響應頭放在中間件

今日內容:

1.content-typedjango

​ Django內置的一個組件,幫助開發者作連表操做. [混搭]json

​ 幫助生成了全部的表跨域

# 幫助你快速實現content_type操做
content_object = GenericForeignKey('content_type', 'object_id')

​ 反向查找的時候方便微信

# 僅用於反向查找
price_police_list = GenericRelation('PricePolicy')
# PricePolicy.objects.create(price='9.9', period='30', content_object=obj)
# 和上面的步驟同樣, 自動拿到兩個id 賦值給兩個

viewsapp

from django.shortcuts import render, HttpResponse
from app01 import models
# Create your views here.

def test(request):
    """
    # # 1. 爲學位課python全棧添加一個價格策略 : 一個月9.9
    obj1 = models.DegreeCourse.objects.filter(title='python全棧').first()
    models.PricePolicy.objects.create(price=9.9, period=30, content_object=obj1)

    obj2 = models.DegreeCourse.objects.filter(title='python全棧').first()
    models.PricePolicy.objects.create(price=15.9, period=60, content_object=obj2)

    obj3 = models.DegreeCourse.objects.filter(title='python全棧').first()
    models.PricePolicy.objects.create(price=22.9, period=90, content_object=obj3)

    # # 1. 爲普通課python全棧添加一個價格策略 : 一個月9.9
    obj1 = models.Course.objects.filter(title='restframework').first()
    models.PricePolicy.objects.create(price=9.9, period=30, content_object=obj1)

    obj2 = models.Course.objects.filter(title='restframework').first()
    models.PricePolicy.objects.create(price=15.9, period=60, content_object=obj2)

    obj3 = models.Course.objects.filter(title='restframework').first()
    models.PricePolicy.objects.create(price=22.9, period=90, content_object=obj3)
    """

    # 3. 根據課程ID獲取課程   # 獲取該課程的全部價格策略 content_type 封裝了方法
    course = models.Course.objects.filter(id=1).first()
    price_policys = course.price_police_list.all()
    print(price_policys)
    # <QuerySet [<PricePolicy: PricePolicy object>, <PricePolicy: PricePolicy object>, <PricePolicy: PricePolicy object>]>
    return HttpResponse('ok')

1568276786745

modelscors

from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
# Create your models here.
class Course(models.Model):
    """
    普通課程
    """
    title = models.CharField(max_length=32)

    # 僅用於反向查找
    price_police_list = GenericRelation('PricePolicy')

class DegreeCourse(models.Model):
    """
    學位課程
    """
    title = models.CharField(max_length=32)
    price_police_list = GenericRelation('PricePolicy')

class PricePolicy(models.Model):
    """
    價格策略
    """
    price = models.IntegerField()
    period = models.IntegerField()
    # table_name = models.CharField(verbose_name="關聯的表名稱")
    # object_id = models.CharField(verbose_name="關聯的表中的數據行的ID")

    # content_type 生成的表名稱
    content_type = models.ForeignKey(ContentType, verbose_name="關聯的表名稱")  #7. course  8 . DegreeCourse
    object_id = models.IntegerField(verbose_name="關聯的表中的數據行的ID")

    # 幫助你快速實現content_type操做
    content_object = GenericForeignKey('content_type', 'object_id')

# 1. 爲學位課python全棧添加一個價格策略 : 一個月9.9
# 1
""" 
obj = DegreeCourse.objects.filter(title='python全棧').first()
# obj.id
cobj = ContentType.objects.filter(models='degreecourse').first()
# cobj.id
PricePolicy.objects.create(price='9.9', period='30', content_type=cobj, object_id=obj.id)
"""
# 2  引入content_object = GenericForeignKey('content_type', 'object_id')
# obj = DegreeCourse.objects.filter(title='python全棧').first()
# PricePolicy.objects.create(price='9.9', period='30', content_object=obj)
# 和上面的步驟同樣, 自動拿到兩個id 賦值給兩個

2.路飛學城(在線教育平臺)運維

  • 醫生學習
  • IT類
  • 英語

公司規模:數據庫設計

部門:

開發:

  • 主站 : 2+1(VUE)
  • 導師後臺: 1
  • 管理後臺: 1
測試: 1
運維: 1
產品經理: 1
UI:1
運營:1
銷售:2
全職導師:2

開發的週期:

第一期: 6個月, 基本的功能,能用(前兩個月能用了,可是出現bug)

第二期: 完善功能

第三期:

開發:

1.需求分析

2.原型+UI

3.數據庫設計

4.功能開發

1568279154940

  • 主站

    • 課程系列
      • 課程列表
      • 課程詳細
      • 價格策略
      • 章節
      • 觀看視頻
      • 用戶評價
      • 常見問題
    • 深科技(*)
      • 文章列表
      • 文章詳細
      • 點贊
      • 收藏
      • 評論
    • 用戶
      • 登陸
      • 註冊
      • 我的中心
    • 購物(****)
      • 加入購物車
      • 結算
      • 當即支付(基於支付寶)
      • 消息推送(基於微信)
  • VUE

相關文章
相關標籤/搜索