课程机构models
from django.db import models
from apps.users.models import BaseModel
class City(BaseModel):
name = models.CharField(max_length=20, verbose_name='城市')
desc = models.CharField(max_length=200, verbose_name='描述')
class Meta:
verbose_name = '城市'
verbose_name_plural = verbose_name
class CourseOrg(BaseModel):
name = models.CharField(max_length=50, verbose_name='机构名称')
desc = models.TextField(verbose_name='描述')
tag = models.CharField(default='全国知名', max_length=10, verbose_name='机构标签')
category = models.CharField(default='pxjp', verbose_name='机构类别', max_length=4,
choices=(('pxjg', '培训机构'), ('gr', '个人'), ('gx', '高校')))
click_nums = models.IntegerField(default=0, verbose_name='点击数')
fav_nums = models.IntegerField(default=0, verbose_name='收藏数')
image = models.ImageField(upload_to='org/%Y/%m', verbose_name='logo', max_length=100)
address = models.CharField(max_length=150, verbose_name="机构地址")
students = models.IntegerField(default=0, verbose_name="学习人数")
course_nums = models.IntegerField(default=0, verbose_name="课程数")
city = models.ForeignKey(City, on_delete=models.CASCADE, verbose_name='所在城市')
class Meta:
verbose_name = '课程机构'
verbose_name_plural = verbose_name
class Teacher(BaseModel):
org = models.ForeignKey(CourseOrg, on_delete=models.CASCADE, verbose_name="所属机构")
name = models.CharField(max_length=50, verbose_name="教师名")
work_years = models.IntegerField(default=0, verbose_name="工作年限")
work_company = models.CharField(max_length=50, verbose_name="就职公司")
work_position = models.CharField(max_length=50, verbose_name="公司职位")
points = models.CharField(max_length=50, verbose_name="教学特点")
click_nums = models.IntegerField(default=0, verbose_name="点击数") # 人气排序用
fav_nums = models.IntegerField(default=0, verbose_name="收藏数")
age = models.IntegerField(default=18, verbose_name="年龄")
image = models.ImageField(upload_to="teacher/%Y/%m", verbose_name="头像", max_length=100)
class Meta:
verbose_name = '教师'
verbose_name_plural = verbose_name
所在城市若使用CharField的话,在之后更新城市的时候不方便,得修改源代码,所以创建了city类。
创建完成后,再将Course的model的外键完善一下。(eg.课程属于哪一个老师)
添加以下两行代码
from apps.organizations.models import Teacher
teacher = models.ForeignKey(Teacher, on_delete=models.CASCADE, verbose_name='讲师')
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。