djangodjango-modelsdjango-admindjango-modeladmin

Django admin do not display all fields


This question is created to help other people with similar problem. I know how to fix the issue, but I'm also interested Why this happens.

In my models.py I've had a model

class CEOSetting(models.Model):
    title = models.CharField('Заголовок', help_text='Содержимое тега <title>. Так-же поддерживает переменные.', max_length=200, blank=True)
    page = models.CharField('Описание страницы', max_length=120)
    key = models.CharField('Ключ', max_length=50, unique=True)
    variables = models.TextField('Доступные переменные', null=True, blank=True)
    description = models.TextField('Meta description', blank=True)
    keywords = models.TextField('Meta keywords', blank=True)
    robots = models.TextField('Meta robots', blank=True)

And registered this model in admin.py

@admin.register(CEOSetting)
class CEOSettingAdmin(admin.ModelAdmin):
    pass

When I've tried to add or edit CEOSetting record in admin, the admin site was showing me only one field (title) and nothing more. Even buttons at bottom of the page were missing.


Solution

  • I've tried lots of different methods to figure out what's the problem and finally understood that <title> in help_text attribute of title field was causing the issue.

    When help_text is rendered, Django treats <title> as opened tag, which remains opened until the end of page.

    I don't know why it works in a such way. As I remember, value in help_text do not render as safe html automatically, but it seems to me that this <title> is treated as opened tag and blocks rendering for any subsequent html.