A
A
Alexander2016-03-07 14:17:29
Django
Alexander, 2016-03-07 14:17:29

Some fields are not showing up in the django admin. Actually, why?

Model:

class Category(MPTTModel):
  ...
  created_at = models.DateTimeField(auto_now_add=True, null=True, blank=True, verbose_name='Дата создания')
  updated_at = models.DateTimeField(auto_now = True, null=True, blank=True, verbose_name='Дата редактирования')
  ...

When editing a record, these fields are not displayed.
Tried to list these fields in admin.py in readonly_fields and in fields - no change.
admin:
from django.contrib import admin
from django_mptt_admin.admin import DjangoMpttAdmin
from .models import Category

class CategoryAdmin(DjangoMpttAdmin, admin.ModelAdmin):
  tree_title_field = 'Категория'
  tree_display = ('name',)
  list_display = ['id', 'name', 'parent', 'thumb', 'alias', 'image']
  search_fields = ['name']
  readonly_fields = ['created_at', 'updated_at', 'thumb']
  fields = (('name', 'alias', 'parent'), 'description', 'image', 'thumb')
  list_display_links = ('name', 'alias', 'thumb')
  prepopulated_fields = {"alias": ("name",)}

admin.site.register(Category, CategoryAdmin)

UP: when adding problematic fields to lisd_display, they are successfully displayed in the list, but not on the edit page.
More thoughts?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Voronkov, 2016-03-07
@alesd

created_at = models.DateTimeField(editable=True, ...)
updated_at = models.DateTimeField(editable=True, ...)

It is connected withauto_now_add=True

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question