Python - Django Migrations and Admin

Getting Started

This is the continuation of our previous tutorial entitled Python - Django Creating Models that tackles about creating our models.

Creating our Migrations

We will now connect this models to our website by creating migrations. 1. Open command prompt of our site, then type: python manage.py makemigrations blog migrate This will create the migration for our blog app and will look for models created in our app. 2. Type: python manage.py migrate

Checking our Migrations

Go to our blog app then open migrations folder. As you can see, we have created a new file which is our migration. filemigrate

Creating our Admin

Now that we have created our connection, we will now create our Admin that will manage our tables. Open command prompt and type: python manage.py createsuperuser This will direct us to create username and password for our admin. creatingadmin

Registering our Table into Admin

Next, we need to register Post table that we have created in our models into our admin. Go to our blog app directory, open admin.py and paste the ff codes:
  1. from django.contrib import admin
  2. from blog.models import Post
  3.  
  4. admin.site.register(Post)

Running our Server

We now then run our server to check our admin. 1. Type: 127.0.0.1:8000/admin/ to go to Admin Login Page. 2. Login the account that we have registered earlier and you should be able to open Admin like this: admin You can then add data to our Post table. After adding data to our Post table, our site should look like this: tabling This end this tutorial. Happy Coding :)

Add new comment