Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Beginner Django admin question - has no attribute 'date_hierarchy'

I'm just learning Django, and I'm trying to set up the admin area for a new project.

I'm getting the following error:

type object 'StopInline' has no attribute 'date_hierarchy'

Here is the model:

from django.db import models

class Line(models.Model):
    name = models.CharField(max_length=200)

class Lap(models.Model):
    line = models.ForeignKey(Line)
    order = models.IntegerField()

class Stop(models.Model):
    name = models.CharField(max_length=200)
    line = models.ForeignKey(Line)
    lap = models.ForeignKey(Lap)
    order = models.IntegerField()
    departsHour = models.IntegerField()
    departsMinute = models.IntegerField()

And here is the admin.py:

from schedule.models import Line, Stop 
from django.contrib import admin

class StopInline(admin.TabularInline):  
    model = Stop
    extra = 3

class LineAdmin(admin.ModelAdmin):  
    model = Line    
    inlines = [StopInline]

admin.site.register(Line, StopInline)

I don't have anything related to a date, so I'm not sure what's going on. Thanks!

like image 739
hookedonwinter Avatar asked Dec 24 '10 05:12

hookedonwinter


Video Answer


1 Answers

admin.site.register(Stop, StopInline) # UNNECESSARY, SEE BELOW
admin.site.register(Line, LineAdmin)

should do it. register expects models and ModelAdmins. You were trying to register to admin Line with StopInline which confused it.

EDIT I realized this about 45 seconds afterwards. You don't need to register StopInline since it's 'included' in LineAdmin.

like image 109
Robert Avatar answered Nov 23 '22 07:11

Robert