I am making an app that has 2 basic functionalities:
(1) create event
- I have a form that captures the event information then add an entry to my database
(2) list event
- Pulls data from the database and display it on a Datagrid
I also have a home page with navigation bar, using the instruction here: Anvil Docs | Navigation
The issue I am facing is that when I add another event, and then go to the list event page, the latest event was not shown.
I have solved it by re-initialising the pages on my home page’s click function, seen below.
However this cause the page load to be slower. Is there a better way to do this?
class Home(HomeTemplate):
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
self.create_event_link.tag.form_to_open=CreateEvent()
self.list_events_link.tag.form_to_open=ListEvents()
def nav_link_click(self, **event_args):
"""A generalised click handler that you can bind to any nav link."""
# Refresh the pages
self.create_event_link.tag.form_to_open=CreateEvent()
self.list_events_link.tag.form_to_open=ListEvents()
# Find out which Form this Link wants to open
form_to_open = event_args['sender'].tag.form_to_open
self.content_panel.clear()
self.content_panel.add_component(form_to_open, full_width_row=True)
