Next I wanted to be able to visualize the racial, party, and gender makeup of City Council in any given year. I had an html GET request to let the user select a year. It was embedded in a try/except block and an if/else conditional block. Since it’s possible for a user to enter a query in the url directly, I wanted a safeguard against query terms that are not integers and against integers that are outside the range of my data. Continue reading
Philadelphia has a reputation for having low turnover among city councilmembers. The city has loosely accurately rosters of each year’s cohort going back to the 1950’s. Election data is maintained only from 1979 on, representing the cohort that started in January 1980, which included newly elected members and re-elected incumbents. So I decided to focus just from 1980 on to ask the question, “How many unique councilmembers have served your district since 1980?” Anti-clickbait: The answer will not astound you. Continue reading
At its heart, my data set is a simple list of city council members’ names, demographics, and details about their terms of service. So I wanted to create a simple page that just shows this as a table, where the user can click to sort by name, dates, etc. Continue reading
So now I had a functional admin panel. But the point of my project was to have a website where users could look up information about city council members.
Now that I set up my modules & populated my database, I moved on the using Django’s built-in admin interface to manage my project. In older versions of Django, admin users were created when the database was set up, using the
python manage.py syncdb command. The newest version of Django decouples setting up the database from setting up users. To create a superuser, I typed:
(citycouncil)$ python manage.py createsuperuser
Now that the database was set up, I wanted to populate it with my data which I was temporarily storing in a couple of csv files.
Django has an API to get you do this but I decided to do this straight from the sqlite shell. I used the sqlite import function to import data into my tables from csv files. It was a bit finicky but I worked it out.