User input creates a new table

hello:

I need to do this in anvil:

if a user wants to create a new project:

  • the user will type the name (project A, for example) in the text box and clicks “create project” button
  • my anvil app will then create a new table with that name and will create 3 columns
  • the user uses the app and saves data to the table
  • the user can create as many projects as the user likes
  • the name of the projects is added to a dropdown list

if a user wants to work on an existing project:

  • there is dropdown list on the right side. default is no project is selected
  • the user scrolls down the list and chooses a name of the project
  • now the user can add data to the table with that name

As of now, i am stuck at no 2: create a new table with user-input name + create 3 columns with preset names
and I’ll still need to set the permission too.

Any advice will be highly appreciated.
thank you
Sid

Welcome to the forums.

Use the “Users” service to manage your logins -
https://anvil.works/docs/users/the_users_table.html
https://anvil.works/docs/users/presenting-a-login-form
https://anvil.works/learn/tutorials/multi-user-apps

Create your table like this :

project_name (text)
user (link to Users table)
column_1 (whatever it needs to be)
column_2 (whatever it needs to be)
column_3 (whatever it needs to be)

When your user creates a new project, add a new row to this table storing the project name they enter and their user object obtained with anvil.users.get_user()

This way you only need one table. Each user will have their own list of projects and each project will have their own data in columns 1 to 3.

Does that make sense?

hi david:

thanks for your advise

it didn’t occur to me that i don’t need to create a new table for each
user and each project
silly me

using the search() method + the correct parameter(s), i can create a
csv file for a specific project and specific user

thanks again

regards,
sid

1 Like

I am really so happy to see some useful idea.

For further shortcuts (suggested reading): https://anvil.works/docs/data-tables/data-security#views

To help ensure that each user accesses only their own data (no one else’s): https://anvil.works/docs/data-tables/data-security#data-security-with-data-tables