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!
admin.site.register(Stop, StopInline) # UNNECESSARY, SEE BELOW
admin.site.register(Line, LineAdmin)
should do it. register
expects models and ModelAdmin
s. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With