This video is available to students only

Adding models to Django

Let's enhance our project a bit

Before we dive into connecting our Django project to the RDS instance, let's enhance our app a bit.

We'll create a simple journal that documents our journey learning to play the Guitar. This will illustrate how Django can connect to the database. You can use these instructions to enable your own Zappa-powered Django project to connect to your RDS instance.

Add the models#

First, let's activate the guitar Django application in the project. We added this app way back when we first set up this Django project, and now we're going to use it.

Next, let's add a model to the guitar app:

And enable the model for the Django admin:

Don't forget to push these changes to the live dev environment:

Initialize the database#

To initialize the database, we have to instruct Django to create migration files:

You should see:

Then let's insert these models into the database. Note we are running this command from the local machine, but we could also use Zappa to invoke the same management commands. Doing it locally saves us from AWS charging us for AWS Lambda time. However, doing from AWS Lambda might be your best option if the database is not publicly accessible.

You should see:

 

This page is a preview of Serverless Django with Zappa

Start a new discussion. All notification go to the author.