赞
踩
MVT设计模式(model模型【操作数据库】、template模板【页面展示】、view视图【处理请求和调用模型模板】)
使用register方法
admin.site.register(Topic TopicAdmin)
装饰器修饰
@admin.register(Topic)
class TopicAdmin(admin.ModelAdmin)
from django.contrib.auth.models import User from django.db import models # Create your models here. class BaseModel(models.Model): created_time = models.DateTimeField(auto_now_add=True, help_text='创建时间') last_modified = models.DateTimeField(auto_now=True, help_text='修改时间') class Meta: abstract = True class Topic(BaseModel): title = models.CharField(max_length=255, unique=True, help_text='话题标题') content = models.TextField(help_text='话题内容') is_online = models.BooleanField(default=True, help_text='话题是否在线') class Comment(BaseModel): content = models.CharField(max_length=255, help_text='话题评论') up = models.IntegerField(default=0, help_text='支持') down = models.IntegerField(default=0, help_text='反对') topic = models.ForeignKey(to=Topic, on_delete=models.SET_NULL, help_text='关联话题表', null=True) class Role(models.Model): name = models.CharField("角色名称", max_length=50, unique=True) # 多对多 users = models.ManyToManyField(to=User)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。