新模型字段未显示在 PythonAnywhere 的管理页面中

时间:2021-04-29 07:47:05

标签: python django pythonanywhere

在 PythonAnywhere 中向我的 models.py 添加新字段时遇到问题。我的models.py 如下所示,我最近在其中添加了描述字段。

class Post(models.Model):
    title = models.CharField(max_length=40, unique=True)
    cover = models.ImageField(upload_to='images/')
    description = models.CharField(max_length=100)
    author = models.ForeignKey(User, on_delete= models.CASCADE,related_name='blog_posts')
    slug = models.SlugField(null=False, unique=True)
    def get_absolute_url(self):
        return reverse('post_detail', kwargs={'slug': self.slug})
    updated_on = models.DateTimeField(auto_now= True)
    shortcontent = models.CharField(max_length=150)
    content = RichTextUploadingField(blank=True)
    created_on = models.DateTimeField(auto_now_add=True)
    language = models.IntegerField(choices=LANGUAGE, default=0)
    status = models.IntegerField(choices=STATUS, default=0)

    class Meta:
        ordering = ['-created_on']

    def __str__(self):
        return self.title

我确实运行了 makemigrations 和 python manage.py migrate 命令,但我的管理页面上没有显示描述字段:

no description field in here

我的 admin.py 看起来像这样:

class PostAdmin(admin.ModelAdmin):
    list_display = ('title', 'status','created_on')
    list_filter = ("status",)
    search_fields = ['title', 'content', 'description']
    prepopulated_fields = {'slug': ('title',)}
    class Media:
        js = ('ckeditor.js',)
        # do not write '/static/ckeditor.js' as Django automatically looks
        # in the static folder

admin.site.register(Post, PostAdmin)

我该怎么做才能确保描述字段显示在我的管理页面上。我在 Pythonanywhere 中使用 Python 3.8。

1 个答案:

答案 0 :(得分:1)

如果我在 PythonAnywhere 的“网络选项卡”中重新加载网络应用程序,问题就会得到解决。