admin.site.register doesn't add my app in admin Django

Question:

I’m trying to see the models in the admin. I’ve tried everything but nothing seems to work, could you help me?

Note: I’ve also tried with admin.autodiscover() but it didn’t work. Also, I have installed the apps correctly and made the migrations without problems.

Here’s what I have in main urls.py:

from django.contrib import admin
from django.urls import path, include
from django.contrib.auth.views import LoginView , logout_then_login

urlpatterns = [
    path('admin/', admin.site.urls),
    path('homebanking/', include('Clientes.urls')),
]

This is in apps.py:

from django.apps import AppConfig


class ClientesConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'Clientes'

This is what I have in settings.py:

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

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

In the models.py from my app, I have:

class Client(models.Model):
    customer = models.ForeignKey(TipoCliente, on_delete=models.CASCADE)
    customer_name = models.TextField()
    customer_surname = models.TextField()
    customer_dni = models.TextField(db_column='customer_DNI', unique=True)  # Field name made lowercase.
    dob = models.TextField(blank=True, null=True)
    branch_id = models.IntegerField()

    class Meta:
        db_table = 'client'

and my admin.py from my app I have:

    from django.contrib import admin

from Clientes.models import Client
# Register your models here.

admin.site.register(Client)

I really don’t know what’s wrong.

Answers:

Delete your existing migrations within <client_folder_name>/migrations/ except __init__.py then python manage.py makemigrations then python manage.py migrate and check again in admin panel.

Answered By: sikepike

You should create admin class so,

Try this:

@admin.register(Client)
class ClientAdmin(admin.ModelAdmin):
    list_display=['id','customer','customer_name','customer_surname'] # include more fields.
Answered By: Sunderam Dubey