startapp organizations
models内容:
from django.db import modelsfrom datetime import datetime# Create your models here.class CityDict(models.Model): name = models.CharField(max_length=100, verbose_name='城市名') desc = models.CharField(max_length=200, verbose_name='城市描述') add_time = models.DateTimeField(default=datetime.now, verbose_name='创建时间') class Meta: verbose_name = '城市' verbose_name_plural = verbose_name def __str__(self): return self.nameclass CourseOrg(models.Model): name = models.CharField(max_length=100, verbose_name='机构名') desc = models.CharField(max_length=300, verbose_name='机构描述') click_nums = models.IntegerField(default=0, verbose_name='点击数') fav_nums = models.IntegerField(default=0, verbose_name='收藏数') image = models.ImageField(max_length=100, verbose_name='封面图', upload_to='static/uploads/orgs/%Y/%m') address = models.CharField(max_length=150, verbose_name='机构地址') city = models.ForeignKey(CityDict, on_delete=models.CASCADE, verbose_name='所在城市') add_time = models.DateTimeField(default=datetime.now, verbose_name='创建时间') class Meta: verbose_name = '课程机构' verbose_name_plural = verbose_name def __str__(self): return self.nameclass Teacher(models.Model): org = models.ForeignKey(CourseOrg, on_delete=models.CASCADE, verbose_name='所属机构') name = models.CharField(max_length=100, verbose_name='教师名') desc = models.CharField(max_length=300, verbose_name='教师描述') work_years = models.IntegerField(default=0, verbose_name='工作年限') work_company = models.CharField(max_length=100, verbose_name='就职公司') work_position = models.CharField(max_length=100, verbose_name='公司职位') points = models.CharField(max_length=100, verbose_name='教训特点') click_nums = models.IntegerField(default=0, verbose_name='点击数') image = models.ImageField(max_length=100, verbose_name='教师图', upload_to='static/uploads/teachers/%Y/%m') fav_nums = models.IntegerField(default=0, verbose_name='收藏数') add_time = models.DateTimeField(default=datetime.now, verbose_name='创建时间') class Meta: verbose_name = '教师' verbose_name_plural = verbose_name def __str__(self): return self.name
每个表都有几个常用的字段,比如name,description,add_time以及meta信息和 __str__ 重载等