【问题标题】:Django model fields don't show up in Admin pageDjango 模型字段未显示在管理页面中
【发布时间】:2023-05-22 12:12:01
【问题描述】:

我是 Django 的初学者,当我尝试在 Django 管理页面上加载所有模型字段时,我无法看到它们。我在设置页面中正确添加了应用程序,对管理页面进行了相对导入,并成功让模型显示在管理页面中,但问题是大多数时候,我输入的字段都丢失了。我通常只显示最后一两个,并且只有当它们是 TextFields 时才显示。

This is all the Fields I enter into the text editor

But this is all I end up seeing

【问题讨论】:

  • 定义你的 ModelAdmin 类,并正确注册它

标签: django model field


【解决方案1】:

在forms.py中使用这个

from yourApp.models import Product 
class ProductForm(ModelForm):
    class Meta:
        model = Product
        fields = '__all__'

在models.py中不要使用>>,

例如:

class Product(models.Model):

    fields1 = models.CharField(max_length=100)
    fields2 = models.CharField(max_length=100)
    tiltle = models.Texfield()

【讨论】:

    【解决方案2】:

    尝试删除大部分行后面的“,”,例如

    tiltle = models.Texfield()
    

    【讨论】: