hierarchy из другой модели.
models.py
class Employee(Uided, Dated, Versioned):
first_name = models.CharField(_('First name'), max_length=255)
last_name = models.CharField(_('Last name'), max_length=255)
middle_name = models.CharField(
_('Patronymic'), max_length=255, blank=True, null=True)
class OrganizationHierarchy(Dated):
slug = models.SlugField(unique=True, editable=False)
name = models.CharField(
_('Title'), max_length=255, unique=True)
class Employment(Dated):
employee = models.ForeignKey(
Employee, related_name='employments',
on_delete=models.CASCADE)
hierarchy = models.ForeignKey(
OrganizationHierarchy,
related_name='employments',
verbose_name=_('Hierarchy'),
on_delete=models.CASCADE)
admin.py
class EmploymentInline(SecureAdminInline):
model = Employment
fields = ('hierarchy',)
@admin.register(Employee)
class EmployeeAdmin(SecureVersionedModelAdmin):
list_display = ('last_name', 'first_name', 'middle_name', 'hierarchy')
list_display_links = ('last_name', 'first_name', 'middle_name')
search_fields = ('first_name', 'last_name', 'middle_name')
fieldsets = ((
None,
{'fields': ('last_name', 'first_name',
'middle_name', 'display_hierarchy')}
))
inlines = [EmploymentInline]
def display_hierarchy(self, obj):
return obj.employments.hierarchy
display_hierarchy.short_description = _('Hierarchy')
Выдает такую ошибку
<class 'staff.admin.EmployeeAdmin'>: (admin.E108) The value
of 'list_display[3]' refers to 'hierarchy', which is not
a callable, an attribute of 'EmployeeAdmin', or an attribute or
method on 'staff.Employee'.
Подскажите, пожалуйста, в чем проблема?
hierarchy это пропертя или что за поле?
Обсуждают сегодня