03 課程相關5張表設計

2022-08-12 08:03:13 字數 3404 閱讀 1810

課程類別

', max_length=16)

sequence = models.integerfield('

展示順序

', default=10)

class

meta:

db_table = '

tb_coursetype

'def

__str__

(self):

return

self.title

class

coursetag(base):

title = models.charfield('

課程標籤

', max_length=16)

sequence = models.integerfield('

展示順序

', default=10)

class

meta:

db_table = '

tb_coursetag

'def

__str__

(self):

return

self.title

class

course(base):

status =(

('0', '

即將上線'),

('1', '

已上線'

), ('2

', '

已下線'

), )

title = models.charfield('

課程名', max_length=24)

desc = models.charfield('

課程描述

', max_length=256)

img = models.imagefield('

課程logo

', upload_to='

course

', null=true)

course_type = models.foreignkey(coursetype, verbose_name='

課程型別

', on_delete=models.set_null, default=none, null=true)

course_tag = models.manytomanyfield(coursetag, verbose_name='

課程標籤')

status = models.charfield('

課程狀態

', choices=status, max_length=8, default='1'

) attention = models.integerfield('

關注人數

', default=0)

learner = models.integerfield('

學習人數

章標題', max_length=24)

serial_num = models.integerfield('

章序號'

) course = models.foreignkey(course, related_name='

chapters

', on_delete=models.set_null, null=true)

class

meta:

db_table = '

tb_chapters

'def

__str__

(self):

return

self.title

class

sections(base):

title = models.charfield('

節標題', max_length=24)

serial_num = models.integerfield('

節序號'

) chapters = models.foreignkey(chapters, related_name='

sections

', on_delete=models.set_null, null=true)

learn_time = models.integerfield('

學習小時

', default=1)

video = models.filefield("

", upload_to="

videos/%y%m%d/

", blank=true, max_length=1024)

seq_num = models.integerfield("

序號", default=1)

class

meta:

db_table = '

tb_sections

'def

__str__

(self):

return self.title

models.py

from django.contrib import

admin

from .models import

sections,chapters,coursetag,coursetype,course

modellist=[sections,chapters,coursetag,coursetype,course]

for model in

modellist:

admin.site.register(model)

python manage.py makemigrations 

python manage.py migrate

3 課程相關5張表設計

課程類別 max length 16 sequence models.integerfield 展示順序 default 10 class meta db table tb coursetype def str self return self.title class coursetag base ...

1911A 課程相關5張表設計

課程類別 max length 16 sequence models.integerfield 展示順序 default 10 class meta db table tb coursetype def str self return self.title class coursetag base ...

建立課程 增加抽象基類 課程相關5張表設計

1.1 建立使用者模型course 1.2 在setting.py中註冊course模型 第一步 1.3 syl urls.py新增路由 第二步 urlpatterns path course include course.urls 1.4 建立 course urls.py路由檔案 第三步 fro...