Django AttributeError: type object ‘*Inline’ has no attribute ‘date_hierarchy’
I work on a simple Django Q&A app and decided that Questions and Answers should be on the same page in the admin. Django already provides that using inlines, but after using it a strange error started appearing (usually on server restart or code reload).
type object 'AnswerInline' has no attribute 'date_hierarchy'
After a bit of digging, I found that I was registering the AnswerInline with the admin, which was not necessary – it was already in the inlines attribute of QuestionAdmin.
Here is the code:
from django.contrib import admin from questions.models import Question, Answer class AnswerInline(admin.TabularInline): model = Answer class QuestionAdmin(admin.ModelAdmin): model = Question inlines = (AnswerInline,) admin.site.register(Question, QuestionAdmin) admin.site.register(Answer, AnswerInline) # This line is not necessary and causes the problem