• Django模型中的admin后台管理无法显示字段


    在执行django后台管理时,登陆到http://127.0.0.1:8000/admin/,进入页面后没有对应的字段显示。请解决?

    代码:

    models.py

    from django.db import models
    
    # Create your models here.
    #发布会表
    from django.db import models
    class Event(models.Model):
        name = models.CharField(max_length = 100)  #发布会标题
        limit = models.IntegerField()              #参加人数
        status = models.BooleanField()               #状态
        address = models.CharField(max_length = 200) #地址
        start_time = models.DateTimeField('events time') #发布会时间
        create_time = models.DateTimeField(auto_now = True) #创建时间
    
        def __str__(self):
            return self.name
    
    #嘉宾表
    class Guest(models.Model):
        event = models.ForeignKey(Event) #关联发布会ID
        realname = models.CharField(max_length = 64) #姓名
        phone = models.CharField(max_length = 16) #手机号
        email = models.EmailField() #邮箱
        sign = models.BooleanField() #签到状态
    create_time = models.DateTimeField(auto_now = True) #创建时间,自动获取当前时间
    
    class Meta:
        unique_together = ('event','phone')
    
    def __str__(self):
        return self.realname
    # Create your models here.
    from django.conf import settings
    
    class Article(models.Model):
        """文章"""
        STATUS_CHOICES = (
            ('d', '草稿'),
            ('p', '发表'),
        )
        COMMENT_STATUS = (
            ('o', '打开'),
            ('c', '关闭'),
        )
        TYPE = (
            ('a', '文章'),
            ('p', '页面'),
        )
        title = models.CharField('标题', max_length=200, unique=True)
        body = models.TextField('正文')
        pub_time = models.DateTimeField('发布时间', blank=True, null=True)
        status = models.CharField('文章状态', max_length=1, choices=STATUS_CHOICES, default='p')
        comment_status = models.CharField('评论状态', max_length=1, choices=COMMENT_STATUS, default='o')
        type = models.CharField('类型', max_length=1, choices=TYPE, default='a')
        views = models.PositiveIntegerField('浏览量', default=0)
        author = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name='作者', on_delete=models.CASCADE)
        article_order = models.IntegerField('排序,数字越大越靠前', blank=False, null=False, default=0)
    
    
        def __str__(self):
            return self.title
    
        class Meta:
            ordering = ['-article_order', '-pub_time']
            verbose_name = "文章"
            verbose_name_plural = verbose_name
            get_latest_by = 'created_time'

    admin.py

    from django.contrib import admin
    from sign.models import Event,Guest
    
    # Register your models here.
    admin.site.register(Event)
    admin.site.register(Guest)

    登陆显示页面如下:

     

    实际应该显示:

  • 相关阅读:
    读书笔记之复盘
    读书笔记之大话设计模式
    代码重构之重命名
    代码重构之下降方法
    代码重构之提升方法
    代码重构之移动方法
    代码重构之封装集合
    JSON之实体对象转JSON字符串,字段名全部转为小写
    SQL代码之多组织数据汇总成树形表格展示
    Python socket学习笔记(三)
  • 原文地址:https://www.cnblogs.com/aszeno/p/10574823.html
一二三 - 开发者的网上家园