Python Django Tutorial: Built-in Admin Interface - Part Five

Today, I will take one new part of Python Django from my tutorial series. In this part you will learn the built-in admin interface in django.

I already told you the following:

Django provides Good Admin interface that's easily handled by admin. Admin can change any table data with easy code in Django.Let’s move to steps of use of admin interface in django.

  1. Firstly Create Django Project with django app according to my above tutorials.

  2. Now create any model in models.py file as below:

    cmd

  3. Now open Command prompt and Migrate this model using some command that I have already told yo in Django tutorial part one.

  4. After Successful migration of database models, now we move to URLS.py file in which we define the url of admin interface.

  5. Now import some libraries in this file like below:

    fromdjango.conf.urlsimport url,include
    from django.contribimport admin

  6. After this add url of admin interface and also include location of method of admin which is already defined as the location of admin .

    urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),

  7. In above code define URL path of admin panel and also define the predefined method location in admin.site.urlsfle.We can edit this file.

  8. Now run django Project and go to http://127.0.0.1:8000/admin/

  9. Now you will see Login Prompt screen like below image:

    cmd

  10. Here you cannot enter in Admin because you don’t allow user to use this admin interface.

  11. Now make user to access to admin interface.

  12. Go to command prompt and open in django rot directory after that write command : python manage.py createsuperuser.

  13. It will ask your username then email id and then Password or confirm password. You can see demo in below image:

    cmd

  14. Now open dajngo admin login form and fill imformation for logged in interface.

  15. After login you will see interface as below image:

    login

  16. Here you always get Groups and Users built-in database structure.Here you can add any user and also make groups with some permission.

  17. Now we Click on Users.

    Click on Users

  18. If you want to add new user for this admin interface click top right link add Users.

  19. Now give username and password and save this information so this user can also be a part of django. But django doesn't give user admin privileges without admin permission. When you save the the user information you will need some other form for that user.

    permission

  20. In above mage you will see a form that is mostly for filling out information for new user. Here superadmin can give permission to use this admin interface and admin can give some type of permission according to  user.

  21. Now go to home again click on user you will see all user list.

    user list

  22. Now the most important part is that we create a model in our project and we want to us that model in admin panel

  23. So now create admin.py file in django app folder where already exist forms.py,models.py file.

  24. After creation of file now we write some code in this file as below image.

    code

  25. In above code from django.contrib import admin access all the admin side method and from main.models import Publisher access the model that we create in models.py file.admin.site.register(Publisher) is used for giving permission to use Publisher in admin interface.

  26. After writing this code in admin.py file Now open admin panel's  home location you will find Publisher model in home admin.

    admin.py file

  27. Now click on Publisher you will see form and their attribute which is defined in a models.py file.

    click on Publisher

  28. Now here you can insert data and create new publisher and save this. It will automatically save all data into database.

So this is the simple use of admin interface .In next article I will tell advanced features of admin interface.

Up Next
    Ebook Download
    View all
    Learn
    View all