Add "shop" Table to Django Admin
In this video we will add our shop database table to our admin view and load some initial records.
At this point you should have most of your app set up along with a superuser account for Django authentication.
What you will do now is register your shop model in the Admin interface. To do so you will subclass a GeoDjango class called OSMGeoAdmin and specifying the list of columns to display for the view.
Welcome to video number nine in our series on creating a location-based web app with Django and GeoDjango. In this video, we will add our
shop database table to our admin view and load some initial records. At this point, you should have most of your app set up, along with a superuser account for Django authentication.
What you will do now is register your
shop model in the admin interface. To do so, you will subclass a GeoDjango class by the name of
OSMGeoAdmin, and specify the list of columns to display for the view.
01:15 Django even capitalized the table name and made it plural for consistency. Let’s look inside. Not surprisingly, we have no shop data yet, but as you can see, the interface has provided a way for us to manually add records if we wanted.
You can take a look inside the file if you’re curious about its structure. But what we’re going to do next is create a Django migration to move this data into our database. To do that, we’re going to execute a
manage.py command to initialize an empty migration for our
First, we’ll stop our site by pressing Control + C, and then clean up our view a little. Notice the
migrations/ folder falls within the app part of our project, within the nearby
shops/ folder. If you expand this, you’ll see artifacts from our previous migration.
Then—and this is the lengthy part—you’ll need to complete the code for the following
load_data() function. The important parts to note here in the function is the name of your app,
'nearbyshops', and the model name that will be needed,
Become a Member to join the conversation.