【问题标题】:New model field is not showing in admin page on PythonAnywherePythonAnywhere 的管理页面中未显示新模型字段
【发布时间】:2021-04-29 07:47:05
【问题描述】:

在 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 命令,但描述字段没有显示在我的管理页面上:

我的 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。

【问题讨论】:

  • 您是否重新加载了网络应用程序?如果您在 PythonAnywhere 上更改了 Web 应用程序的源代码,则需要在之后重新加载 Web 应用程序才能使更改生效。

标签: python django pythonanywhere


【解决方案1】:

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

【讨论】: