Let’s switch to the Code View for our ArticleEdit Form.

You will see some import statements and a Python class called ArticleEdit that describes how the ArticleEdit Form behaves. Any code we write here will run on the user’s browser.

Let’s now search through the Categories Data Table and store the results in a variable. We can access any Data Table with app_tables.<data-table-name>. Because we added Data Tables to our app, you should see the following import statement has automatically been added to the Form code:

from anvil.tables import app_tables

Add this to the __init__ function of the class:

self.categories = [
  (cat['name'], cat) for cat in app_tables.categories.search()
]

This creates a list of 2-tuples of the form:

[
    ("First category name", <first_row_from_table>),
    ...,
    ("Final catgegory name", <final_row_from_table>)
]

The first element of each tuple is what will be displayed in the DropDown box. The second element of the tuple becomes the selected_value property of the DropDown if that option is selected.