Skip to main content

Django Admin Interface

Here you will learn about working with django admin interface. 

Prerequiests: It is necessary to learn about models first before working with Django admin panel. You can learn about models here.

What is admin.py File in Django?

We’ve created an app and a model in previous articles. But we haven’t stored anything yet to our database. Django’s admin interface will help us to add, edit and delete the data from the database using the models. As we know models are the structure of our database tables, we can add a new object, edit it and delete objects from database in two ways either by coding or by using a graphical user interface. That graphical user interface to store, edit and delete data from database is Django admin interface.

Django Admin Interface 1 Django Admin Interface 2

In above screenshots, first is a screenshot of admin page which requires the login to do any changes in database, that’s why it is secured way to work with database and in second image you can see some Models that we have added to admin interface.

Working with Django Admin Panel

As mentioned above, before working with database first you should have created a model. As in previous article we created a model (having ImageField and CharField) named as Job. Now we’ll add this model to admin interface so we can store data in ImageField and CharField using Django’s admin.

Django Admin Interface 3

So let’s start.

Step 1: Create a User Account

Run your project and open admin page (for example – http://127.0.0.1:8000/admin or localhost:8000/admin/).

Django Admin Interface 4

So a username and password is required to move forward,  means we need to create an account. To create it open your terminal and stop the server then type this command –

python manage.py createsuperuser

Django Admin Interface 5

After hitting enter it will ask you for an username, you can type any username but if don’t enter anything and just hit enter then it will take your computer name as username. Let’s say we have created username as thecrazyprogrammer.

Django Admin Interface 6

After username, it will ask  your email address and a password. So after creating a username let’s run your server again and open localhost:8000/admin again, then login with your username and password you’ve entered above.

Note: If you forgot your password later, then there is no need to worry. As long as you have access to your server you can change it.

Django Admin Interface 7

Django Admin Interface 8

So now you’ve access to the Django admin page. At present there is only options are showing which can be used to add or see the new username and groups. But our created model Job is still not shown up.

Step 2: Register Your Model in admin.py

To register your model in admin.py, open the admin.py inside the same app directory where is your models.py (model to be added) is present.

Django Admin Interface 9

Now inside this file write the code as shown below .

from django.contrib import admin

from .models import Job

admin.site.register(Job)

Django Admin Interface 10

Here Job is the name of our model that we want to register. Now save that file and reload the admin page in browser and you’ll get Job model in the Django’s admin.

Django Admin Interface 11

Step 3: Add, Edit and Delete Data (Objects) from Database

Django Admin Interface 12

Here JOBS in red square is name of the APP and Job in green square is the model. As we can add more than one model in an app it will be shown under the JOBS app.

Now open the Jobs model.

Django Admin Interface 13

Currently there is nothing in the database. To add it click on Add Job button at right of the screen. Then you will see that the fields we’ve specified in the Model will be shown up here.

Django Admin Interface 14

Add data and save it.

Django Admin Interface 15

And our data is stored into database. Now you may have got the idea that how easy is working with Django. We didn’t need to specify the queries to store the data into database. It will be very helpful, let’s say you have a website running on server. You want to change/delete/add some data. All you have to do is login to your admin interface and update it using Django admin and your site will be up to date.

That’s all

I hope you’ve understood the basic idea of storing data into database using Django’s admin interface. We’ll also see how to fetch data from database in other articles. If you’ve any problem related to this article then please let us know in comment box, We’ll reply as soon as possible.

The post Django Admin Interface appeared first on The Crazy Programmer.



from The Crazy Programmer https://www.thecrazyprogrammer.com/2019/01/django-admin-interface.html

Comments

Popular posts from this blog

Rail Fence Cipher Program in C and C++[Encryption & Decryption]

Here you will get rail fence cipher program in C and C++ for encryption and decryption. It is a kind of transposition cipher which is also known as zigzag cipher. Below is an example. Here Key = 3. For encryption we write the message diagonally in zigzag form in a matrix having total rows = key and total columns = message length. Then read the matrix row wise horizontally to get encrypted message. Rail Fence Cipher Program in C #include<stdio.h> #include<string.h> void encryptMsg(char msg[], int key){ int msgLen = strlen(msg), i, j, k = -1, row = 0, col = 0; char railMatrix[key][msgLen]; for(i = 0; i < key; ++i) for(j = 0; j < msgLen; ++j) railMatrix[i][j] = '\n'; for(i = 0; i < msgLen; ++i){ railMatrix[row][col++] = msg[i]; if(row == 0 || row == key-1) k= k * (-1); row = row + k; } printf("\nEncrypted Message: "); for(i = 0; i < key; ++i) f...

Data Encryption Standard (DES) Algorithm

Data Encryption Standard is a symmetric-key algorithm for the encrypting the data. It comes under block cipher algorithm which follows Feistel structure. Here is the block diagram of Data Encryption Standard. Fig1: DES Algorithm Block Diagram [Image Source: Cryptography and Network Security Principles and Practices 4 th Ed by William Stallings] Explanation for above diagram: Each character of plain text converted into binary format. Every time we take 64 bits from that and give as input to DES algorithm, then it processed through 16 rounds and then converted to cipher text. Initial Permutation: 64 bit plain text goes under initial permutation and then given to round 1. Since initial permutation step receiving 64 bits, it contains an 1×64 matrix which contains numbers from 1 to 64 but in shuffled order. After that, we arrange our original 64 bit text in the order mentioned in that matrix. [You can see the matrix in below code] After initial permutation, 64 bit text passed throug...

dotnet sdk list and dotnet sdk latest

Can someone make .NET Core better with a simple global command? Fanie Reynders did and he did it in a simple and elegant way. I'm envious, in fact, because I spec'ed this exact thing out in a meeting a few months ago but I could have just done it like he did and I would have used fewer keystrokes! Last year when .NET Core was just getting started, there was a "DNVM" helper command that you could use to simplify dealing with multiple versions of the .NET SDK on one machine. Later, rather than 'switching global SDK versions,' switching was simplified to be handled on a folder by folder basis. That meant that if you had a project in a folder with no global.json that pinned the SDK version, your project would use the latest installed version. If you liked, you could create a global.json file and pin your project's folder to a specific version. Great, but I would constantly have to google to remember the format for the global.json file, and I'd constan...