标签:图片 创建 注册 手机 delete 用户 alt 课程 def
添加operations模块,models内容为:
from django.db import models from datetime import datetime from users.models import UserProfile from courses.models import Course # Create your models here. class UserAsk(models.Model): name = models.CharField(max_length=100, verbose_name=‘咨询者姓名‘) mobile = models.CharField(max_length=11, verbose_name=‘手机‘) course_name = models.CharField(max_length=50, 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 class CourseComment(models.Model): user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name=‘用户‘) name = models.CharField(max_length=100, verbose_name=‘评论名‘) course = models.ForeignKey(Course, on_delete=models.CASCADE, verbose_name=‘课程‘) comments = 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.name class UserFavorite(models.Model): user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name=‘收藏用户‘) name = models.CharField(max_length=100, verbose_name=‘收藏名‘) fav_id = models.IntegerField(default=0, verbose_name=‘数据ID‘) fav_type = models.IntegerField(default=1, choices=((1, ‘课程‘), (2, ‘机构‘), (3, ‘教师‘)), 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 class UserMessage(models.Model): # user发送的消息,有发送给单个用户,也有发给全体或多个用户 # 本例中 0 是全体接收消息用户,非0则是指定的消息接收用户id user = models.IntegerField(default=0, verbose_name=‘接受消息用户id‘) name = models.CharField(max_length=100, verbose_name=‘消息名‘) message = models.CharField(max_length=500, verbose_name=‘消息内容‘) has_read = models.BooleanField(default=False, 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 class UserCourse(models.Model): user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, verbose_name=‘用户‘) name = models.CharField(max_length=100, verbose_name=‘用户课程名‘) course = models.ForeignKey(Course, 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.name
创建好各个模块后,需要在settings中添加注册相应的模块,这样才可以进行数据的迁移。比laravel等的数据迁移代码量少很多啊。
标签:图片 创建 注册 手机 delete 用户 alt 课程 def
原文地址:https://www.cnblogs.com/andu99/p/8981918.html