Day 7 of Hanukkah at Anvil

Build a web app for each night of Hanukkah, with nothing but Python!

Much like Find My Menorah, this app uses the power of Data Tables. This time, we’re building a simple movie recommendation database.

Categorising movies

Using two linked Data Tables, we can add some movie genres to each possible choice, so users can narrow down what they might like to see. To do this we add a separate table, categories and a column in the movies table linked to the Rows of categories. This is so a movie can have more than one genre. For instance, “Fiddler on the Roof” is both “classic” and a “musical”.

We add a column linked to the Rows of categories table.

We add a column linked to the Rows of categories table.

Then whenever the user spins the dreidel, we select a random choice from the subset of movies that match the category they want.

movies = [m for m in app_tables.movies.search(genre=[self.genre_dropdown.selected_value]) ]
chosen = choice(movies)

self.movie_image.source = chosen['image']
self.movie_description.text = chosen['description']
self.movie_name.text = "{} ({})".format(chosen['name'], chosen['year'])
self.more_link.url = chosen['link']

Spin the Dreidel - adding GIFs to Anvil

Mesmerising, isn’t it…

Mesmerising, isn’t it…

An extra fun touch is the loading animation, a spinning dreidel. I added an Image component for this, with a link to the gif. The trick to get it to animate is to upload the GIF as an Asset rather than clicking the Upload button - otherwise it’ll be auto-converted into a JPEG. Then all you need to do is set the Image’s source to point to the asset _/theme/dreidel.gif.

It’s a nice way to make users feel that the page is doing something interesting behind the scenes while they wait for the results of their button click.

If you want to look at the app code yourself, grab the clone link here!


Give the Gift of Python

Share this post:


Get tomorrow's app in your inbox

Don't miss a day! We'll mail you a new web app every night of Hanukkah: