· 

Django: admin.py

1. Introduction

How can I display some data from the database on the admin page?

Are Groups and Users automatically displayed on the page?

 

2. admin.py

How can I display tables on the admin site?

 

In Django, if you want a model’s table (like your ClientDocument) to be visible and manageable in the Django admin site, you need to register the model in the app’s admin.py file.

Here’s how you do it step by step:


1. Open your app’s admin.py file
For example, if your app is called myapp, open:

myapp/admin.py

2. Import your model

from django.contrib import admin
from .models import ClientDocument

3. Register your model
Basic registration:

admin.site.register(ClientDocument)

This will make the table appear in the admin site with default settings.


4. (Optional) Customize how it looks
If you want more control over how it’s displayed (columns, filters, search), you can use a ModelAdmin class:

@admin.register(ClientDocument)
class ClientDocumentAdmin(admin.ModelAdmin):
list_display = ("file", "owner", "uploaded_at")
list_filter = ("uploaded_at", "owner")
search_fields = ("file", "owner__username")

5. Make sure the admin site is enabled
In your mysite/urls.py (project’s urls.py), ensure you have:

from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]

6. Create a superuser to log in
If you haven’t already:

python manage.py createsuperuser

Then enter username, email, and password.


7. Log in and check
Run the server:

python manage.py runserver

Open http://127.0.0.1:8000/admin/, log in with the superuser credentials, and you should see Client Documents listed.


 

If you want, I can show you how to make the ClientDocument table display with the owner’s username and file link directly in the admin list so it’s more user-friendly.

 

3. Groups and Users are automatically displayed

I opened my admin site:

https://myid.pythonanywhere.com/admin/

In the Authentication and Authorization, there are Groups and Users. I didn't modify admin.py like admin.site.register(ClientDocument). Are Groups and Users automatically displayed on the admin site?

 

Yes — exactly!

  • Django automatically registers its built-in User and Group models in the admin site.

  • That’s why you see Groups and Users under “Authentication and Authorization” without doing anything in your app’s admin.py.

Any model that comes built into Django, like User and Group from django.contrib.auth, is pre-registered so you can manage them right away.

For your custom models (like ClientDocument or ClientProfile), you must register them yourself in your app’s admin.py to make them appear in the admin.

Example:

from django.contrib import admin
from .models import ClientDocument
admin.site.register(ClientDocument)

After that, ClientDocument will show up in your admin site just like Users and Groups.

 

Do you want me to show how to make it display nicely with owner username and upload date?