After changing the model, the admin panel stopped showing the model fields. That is, they are shown in the general list, and when opening any particular model, just an empty admin window with “delete”, “save”, etc. buttons. Changes in the model are also quite simple: deleted the TextField field, added the ForeignKey field. Migrations made, in admin.py mention of the old field was also deleted.

The model code and the corresponding model in the admin panel are listed below.

 class DocumentModel(models.Model): title = models.CharField(max_length=100, db_index=True) url_address = models.CharField(max_length=255, blank=True, null=True, db_index=True) text_document = models.ForeignKey(DocumentTextModel, blank=True, null=True, verbose_name=u'Контент', db_index=True) #text_doc = models.TextField(blank=True, null=True, verbose_name=u'Контент') visible_left = models.BooleanField(verbose_name=u'Левый столбец', db_index=True) visible_right = models.BooleanField(default=True, verbose_name=u'Правый столбец', db_index=True) visible_middle = models.BooleanField(default=True, verbose_name=u'Центр главной страницы', db_index=True) changedate = models.DateTimeField(auto_now=True, verbose_name=u'Дата изменения', db_index=True) class DocumentAdminModel(admin.ModelAdmin): ordering = ['changedate'] list_display = ('title', 'changedate', ) list_filter = ('changedate') # resize CharField in Form formfield_overrides = { # Django enforces maximum field length of 14 onto 'title' field when user is editing in the change form models.CharField: {'widget': forms.TextInput(attrs={'size':'300'})}, } # search in model search_fields = ['title', ] 

I also post a screenshot of the admin panel: Blank interface

    1 answer 1

    You forgot to list the model fields in the fields attribute:

     class DocumentAdminModel(admin.ModelAdmin): fields = ('title', 'url_address' ..) 
    • Thank you, the fields have appeared. And then you can still ask why in other models without specifying the fields, everything usually works? It just turns out that there I hide some fields through editable = False, and here, on the contrary, all fields are hidden and I have to prescribe which ones to show. - Legal Acts
    • Yes, there is again this problem. If you add the 'text_document' field to the fields, the page again becomes empty. - Legal Acts
    • @LegalActs you are somewhere tangled, without fields fields will always be empty, and the text_document is a ForeignKey field, it should be displayed by default as a list of DocumentTextModel models - Ivan Semochkin
    • If no fields are specified, then all fields that do not have editable = False or which are not AutoField are displayed. Docs.djangoproject.com/en/1.9/ref/contrib/admin/… - Chikiro
    • You have some problem with the display of the text_document field in the admin panel. - Chikiro