Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
models not showing on django admin

I'm just starting my first project using Django 1.11. I followed the same steps I've used on multiple Django 1.10 projects, but for some reason my models are not showing up on my localhost/admin site.

My INSTALLED_APPS from settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'home.apps.HomeConfig',
]

My admin.py:

from django.contrib import admin

from home.models import Home

# begin Admin Class Definitions
class HomeAdmin(models.ModelAdmin):

    fieldsets = [
        ('Title', {'fields': ['title']}),
        ('Publication Date', {'fields': ['pub_date']}),
        ('Home Page Text', {'fields': ['header', 'sub_header', 
         'link_text']}),
    ]
    list_display = ('title', 'pub_date')
    list_filter = ['pub_date']

admin.site.register(Home, HomeAdmin)

My [main_app]/urls.py:

from django.conf.urls import url, include
from django.contrib import admin

admin.autodiscover()

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include('home.urls'))
]

But when I go to localhost:8000/admin the only things present are Groups and Users as if I hadn't registered any models at all.

I have run makemigrations and migrate, and I have tried putting admin.py within the app directory instead of the project directory. It's currently in the [project_name]/[project_name] directory (the one with settings.py, urls.py, and wsgi.py files).

Any suggestions?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I think you have to register your models to the admin. I normally do it like this if it's a simple model.

    from django.contrib import admin
    from .models import *

    # Register your models here.
    @admin.register(Model)
    class ModelAdmin(admin.ModelAdmin): pass
about 4 years ago · Santiago Trujillo Report

0

I gave up trying to diagnose my problem, and nuked the project and started over. It works fine now. I'm honestly not sure what the problem was. If anyone is curious, here are my new files:

from settings.py:

INSTALLED_APPS = [
    'home',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

from urls.py:

from django.conf.urls import url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
]

from admin.py:

from django.contrib import admin

# Register your models here.
from .models import HomePageText

admin.site.register(HomePageText)

I honestly don't understand why it wasn't working before. If anyone with more insight can spot some difference that I can't please let me know.

about 4 years ago · Santiago Trujillo Report

0

When I use the Django admin always import in this form:

from django.contrib import admin

And inherint in the class:

class HomeAdmin(admin.ModelAdmin):

So your admin.py file would looke like this:

from django.contrib import admin

from home.models import Home

# begin Admin Class Definitions
class HomeAdmin(admin.ModelAdmin):

    fieldsets = [
        ('Title', {'fields': ['title']}),
        ('Publication Date', {'fields': ['pub_date']}),
        ('Home Page Text', {'fields': ['header', 'sub_header', 
         'link_text']}),
    ]
    list_display = ('title', 'pub_date')
    list_filter = ['pub_date']

admin.site.register(Home, HomeAdmin)
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!