Conteúdo do Curso
Django ORM Ninja: Advanced Techniques for Developers
Django ORM Ninja: Advanced Techniques for Developers
Admin Interface
Django allows you to manage content using the Admin page. Now we will set up the admin panel to see our database through the Django server.
Go to urls.py. We can see that the standard endpoint of the admin page is already indicated, and let's learn how to run our project.
For this, we write the command:
Clicking on the link http://127.0.0.1:8000/
takes us to the base of our Django project. Now, if we navigate to the http://127.0.0.1:8000/admin/
endpoint, we'll arrive at the default admin panel interface.
However, we're unable to access it at the moment since our database currently has no users. To resolve this, we need to go back to our project and use the console to execute a command that will assist in creating an admin user.
Enter a username, email, and a secure password, but remember it.
Let's return to our admin panel and enter our username and password. Now we are inside the standard admin panel. We don't have anything here yet, no models. For this, we need to register models in the admin.
In our project, we open the admin.py file. First, let's try the standard registration, for example:
Go back to the page and see that our first model has appeared. We can create our first instance by clicking the +Add button. For example, biography. Now, we have the first object in our database.
Return to our admin.py file.
Let's register all our models Author and Book.
For now, we will not delve into all the details of registration in the admin panel. Standard settings will suffice for us to check the status of our database.
__init__.py
bookstore
.idea
inspectionProfiles
profiles_settings.xml
.gitignore
bookstore_orm.iml
misc.xml
modules.xml
workspace.xml
app
__init__.py
asgi.py
settings.py
urls.py
wsgi.py
db
migrations
__init__.py
__init__.py
admin.py
apps.py
models.py
tests.py
views.py
data.json
manage.py
requirements.txt
Obrigado pelo seu feedback!