如何从django管理面板中删除额外的“s”?

时间:2021-12-20 20:41:00

I am really very much irritated by the extra "s" added after my class name in django admin eg class 'About' in my model.py becomes 'Abouts' in admin section. And i want it not to add extra 's'. Here is my model.py file-

在django admin中我的班级名称之后添加的额外“s”让我非常恼火,例如我的model.py中的“关于”类在管理部分变为“关于”。我希望它不要添加额外的's'。这是我的model.py文件 -

class About(models.Model):
        about_desc = models.TextField(max_length=5000)

        def __unicode__(self):              # __str__ on Python 3
                return str(self.about_desc)

Please anybody suggest me how django can solve my problem.

请有人建议我django如何解决我的问题。

2 个解决方案

#1


15  

You can add another class called Meta in your model to specify plural display name. For example, if the model's name is Category, the admin displays Categorys, but by adding the Meta class, we can change it to Categories.

您可以在模型中添加另一个名为Meta的类来指定多个显示名称。例如,如果模型的名称为Category,则admin将显示Categorys,但通过添加Meta类,我们可以将其更改为Categories。

I have changed your code to fix the issue:

我已更改您的代码以解决此问题:

class About(models.Model):

    about_desc = models.TextField(max_length=5000)

    def __unicode__(self):              # __str__ on Python 3
        return str(self.about_desc)

    class Meta:
        verbose_name_plural = "about"

For more Meta options, refer to https://docs.djangoproject.com/en/1.8/ref/models/options/

有关更多Meta选项,请参阅https://docs.djangoproject.com/en/1.8/ref/models/options/

#2


4  

Take a look at the Model Meta in the django documentation.

看一下django文档中的Model Meta。

Within a Model you can add class Meta this allows additional options for your model which handles things like singular and plural naming.

在模型中,您可以添加类Meta,这允许您的模型的其他选项处理诸如单数和复数命名之类的事情。

This can be used in the following way (in english we do not have sheeps) so verbose_name_plural can be used to override djangos attempt at pluralising words:

这可以通过以下方式使用(在英语中我们没有羊)因此verbose_name_plural可用于覆盖djangos尝试复数词:

class Sheep(model.Model):
    class Meta:
        verbose_name_plural = 'Sheep'

#1


15  

You can add another class called Meta in your model to specify plural display name. For example, if the model's name is Category, the admin displays Categorys, but by adding the Meta class, we can change it to Categories.

您可以在模型中添加另一个名为Meta的类来指定多个显示名称。例如,如果模型的名称为Category,则admin将显示Categorys,但通过添加Meta类,我们可以将其更改为Categories。

I have changed your code to fix the issue:

我已更改您的代码以解决此问题:

class About(models.Model):

    about_desc = models.TextField(max_length=5000)

    def __unicode__(self):              # __str__ on Python 3
        return str(self.about_desc)

    class Meta:
        verbose_name_plural = "about"

For more Meta options, refer to https://docs.djangoproject.com/en/1.8/ref/models/options/

有关更多Meta选项,请参阅https://docs.djangoproject.com/en/1.8/ref/models/options/

#2


4  

Take a look at the Model Meta in the django documentation.

看一下django文档中的Model Meta。

Within a Model you can add class Meta this allows additional options for your model which handles things like singular and plural naming.

在模型中,您可以添加类Meta,这允许您的模型的其他选项处理诸如单数和复数命名之类的事情。

This can be used in the following way (in english we do not have sheeps) so verbose_name_plural can be used to override djangos attempt at pluralising words:

这可以通过以下方式使用(在英语中我们没有羊)因此verbose_name_plural可用于覆盖djangos尝试复数词:

class Sheep(model.Model):
    class Meta:
        verbose_name_plural = 'Sheep'