Add Models in Django Admin – admin.py
Even though you have migrated Django models into a database, you cannot see it instantly. The quickest way to see the database is through the Django admin site. To see your database in the Django admin site, you need to add some code in the admin.py file under the app directory.
To check the status, run the runserver
command.
python manage.py runserver
Go to localhost:8000/admin/ in your browser. You can confirm that there is no model besides the models already prepared (i.e., Groups and Users).
Edit admin.py
Adding new models to the admin.py file is straightforward.
You need to import a model you want to add and register the model. You can register the two models we created in the previous sections by adding the yellow line below.
from django.contrib import admin
# Register your models here.
from .models import Employee
from .models import Division
admin.site.register(Employee)
admin.site.register(Division)
Go to localhost:8000/admin/ again. You'll see that the two models are added to the admin site. You can manage the process to update the admin.py file without stopping and re-running the runserver
command.