I want to know how to assign multiple different email address to a simple objects column and then reference it when I need to check
For example I have a textarea element that I want admin to enter multiple emails and perhaps use a “,” to separate them. They are users assigned to an Admin as an example. I know how to add them to a database using the text area, but how would I access it individually?
Text area user entered tony@gmail.com, Jack@gmail.com, Marti@gmail.com right. I got it to save into a simple object column, but how do I access just a single email from that list?
Simple object columns are powerful, because you can store Python data structures directly into them. For example, you can store a Python list, or a Python dictionary (or a Python list of dictionaries, etc) directly into the simple object column.
What you’re storing is a string, which is not the purpose of a simple object column. You should take your string of email addresses, process it and create a Python list of strings. Then put that list of strings into the simple object column.
When you later read the simple object column, you get a list of strings out of it, and can use list indexing to get to individual elements.
Can you give me an example of how to process my example or an idea? I have created python lists before, but have not taken a list from an input like a textbox and processed it.
For non-Anvil related Python questions, a Google search is typically a good start. Try searching on create python list from string. Once you’ve used one of the examples from the search results and if you’re still having trouble, post back here with the code you’re trying.
@jshaffstall I thought I got it to work, but it broke something else hehe… So now my save_to_company_database_click(self, **event_args) does not work after I created a new button and function to update just the company reps column of my data table.
I am not getting any error message to help find the problem, so its probably something weird I am doing.
def save_to_company_database_click(self, **event_args):
company_info = app_tables.company_info.get(Email=anvil.users.get_user()['email'])
if company_info:
company_info['Company_Name'] = self.company_name_textbox.text
company_info['Admin'] = self.admin_textbox.text
company_info['Email'] = self.email_textbox.text
company_info['Phone_Number'] = self.phone_number_textbox.text
company_info['Company_Representatives'] = self.company_reps_textbox.text
alert("records have been updated")
else:
app_tables.company_info.add_row(Company_Name=self.company_name_textbox.text,
Admin=self.admin_textbox.text,
Email=anvil.users.get_user()['email'],
Phone_Number=self.phone_number_textbox.text,
Address=self.company_address_textbox.text,
Company_Representatives=self.company_reps_textbox.text
)
def button_update_company_reps_click(self, **event_args):
reps = self.company_reps_textbox.text
list_of_reps = reps.split(",")
company_info_update = app_tables.company_info.get(Email=anvil.users.get_user()['email'])
if company_info_update['Company_Representatives'] != self.company_reps_textbox.text:
company_info_update['Company_Representatives'] = list_of_reps
alert("Records have been updated")
else:
alert("Company representatives cannot be updated. Error 111")
Problem 2: I think I did the if/else statement incorrectly. It seems to always result in True regardless if I change the self.company_reps_textbox text.
def button_update_company_reps_click(self, **event_args):
reps = self.company_reps_textbox.text
list_of_reps = reps.split(",")
company_info_update = app_tables.company_info.get(Email=anvil.users.get_user()['email'])
if company_info_update['Company_Representatives'] != self.company_reps_textbox.text:
company_info_update['Company_Representatives'] = list_of_reps
alert("Records have been updated")
else:
alert("Company representatives cannot be updated. Error 111")
Consider that you are now writing a list into the database column. When you read it, you’ll get the same list back out. That’s probably not what the TextArea is expecting to see.
In addition to the suggestion about what happens to the list when you get it out of the data table, think about what the above line is doing versus what these lines are doing:
You’ve got a mismatch there.
Beyond those things we can observe from the code snippets, it’s hard to even know what else might be going wrong because we still don’t know how you know something is going wrong. You say the code stopped working, but don’t say how you know it isn’t working. There’s some observable behavior that isn’t what you expect (something in the UI isn’t showing right, something in the data table isn’t right, etc).
You are expecting to see some behavior, but instead are seeing some other behavior. It’s very hard to comment until we know what both of those behaviors are. They’re dead obvious to you, but at this distance, not to us.
The function above is supposed to update the textboxes and the data table with any changes I make in the textboxes after clicking on “SAVE”. Since the iteration of the new function
The initial function stopped working and does not produce an error. It was saving data to the data table and alerting “Records have been updated” but now nothing.
I cant figure out why it won’t save the changes made in the textboxes