Bold dream
Imagination is limitless. So is stupidity.

Django AttributeError: type object ‘*Inline’ has no attribute ‘date_hierarchy’

January 29th 2010 in Default

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



required



required - won't be displayed


Your Comment:

Problem

From time to time one needs to fetch a random row from a table in a db.

Solution

Take one

The “obvious” solution is to order by RAND() and get the first:

SELECT * FROM users ORDER BY RAND() LIMIT 1; /* Don’t do that */

It does the job, problem solved!

Well, no, not exactly! While it works, the [...]

Previous Entry

I found this amazing image stream on flickr (via):

Next Entry

Blogroll