0

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.

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40

2 Answers2

1

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.
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
0

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.

sikepike
  • 3
  • 2
  • Hi, thanks for your answer. How can i delete the existing migrations except init.py? (the command in vsc code) – Maximiliano Rodriguez Aug 12 '22 at 05:34
  • You simply have to delete them just like normal files, In your file explorer tab in VS Code select your app in which Clientes model is written, you will see migrations folder in it, delete all files in there except ___init___.py file. – sikepike Aug 12 '22 at 06:38
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 15 '22 at 06:39