Home > database >  Can not see an app with name "advertisements" in admin interface
Can not see an app with name "advertisements" in admin interface

Time:04-02

When I add an app with the name advertisements (add models, admin register in INSTALLED_APPS) it is not listed in the admin interface (it is very hard to see but it disappears after microseconds).

models.py:

from django.db import models

# Create your models here.

class Advertisement(models.Model):
    pass

admin.py:

from django.contrib import admin

from .models import Advertisement

# Register your models here.
@admin.register(Advertisement)
class AdvertisementAdmin(admin.ModelAdmin):
    pass

apps.py:

from django.apps import AppConfig


class AdvertisementsConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'advertisements'

settings.py:

INSTALLED_APPS = [
    # ...
    "advertisements",
]

Changing an app directory to something like advertisements2, app name (in apps.py) to advertisements2 solves the problem.

Why the app with the name 'advertisements' is not listed in the admin interface?" What is the issue with the name "advertisements"?

I tested in many times in completely blank project.

CodePudding user response:

Try using admin.site.register(Advertisement) instead of the AdminView in admin.py. If this line works, you could add the model admin view individually like this:

class AdvertisementAdmin(admin.ModelAdmin):
    pass

admin.site.register(Advertisement, AdvertisementAdmin)

CodePudding user response:

The question seemd to be a bit strange for me at the beginning and I was feeling super curious about what is going on. I recreated your code perfectly and I was getting the same result as you. No advertisemets app in admin panel. I started a debugger and tracked execution line by line, and everything seemd to be in order. But after some time it occured to me, that it could not be actually django's fault. And it is not! Beware the most intriguing solution to your problem:

Just disable your adblocker and refresh the site!

What is most problably the problem (and what was the problem on my site) is that my adblocker blocked the word advertisement and all the styles that came with it. So with your adblocker turned on, if you were to inspect a site you would see your advertisements app sitting comfortably in your html code:

<div >
      <table>
        <caption>
          <a href="/admin/advertisements/"  title="Models in the Advertisements application">Advertisements</a>
        </caption>
        
          <tbody><tr >
            
              <th scope="row"><a href="/admin/advertisements/advertisement/">Advertisements</a></th>

If you were to remove app-advertisements class from <div > (again, with the adblocker still turned on) the Advertisement should magically apear in admin panel.

  • Related