0

In my application, one has urls and tags. What I'm doing is when the user entering data for an url, he/she will also select relative tags.

I store urls and tags into two different tables and I plan to use a reference table which describe the many-to-many relationship between tags and urls.

I could tell which tags are selected by the user. (as each tag has a boolean variable for that purpose.)

So when the user creating 1 new url and select 5 tags, when he click the submit button, it seems a lot need to happen in the backend: submit 1 SQLFORM for creating that url + creating 5 SQLFORMs each describes a relationship between a tag and the new url.

I have no idea how to accomplish this in web2py.

Am I doing it the right way?

Thanks for your helps in advance!!

fuiiii
  • 1,359
  • 3
  • 17
  • 33
  • Can you show some code so we have an understanding of what you already have working? Assuming you have a form that includes the URL record as well as the list of tags, there should be no need to create additional SQLFORMs for the tags. Just loop through the submitted tags and do an insert into the link table for each one. – Anthony May 14 '14 at 11:45

1 Answers1

0

I ended up by created an "tags" filed in the url table and only submit one form.

Anthoy is probably right about using insert for each tag, but selected tags data are in angularJS' variable and it's too much trouble to pass the variable to python/web2py and also invoke a python function.

I probably didn't use the right way to do many-to-many-relationship in web2py. :/

Another relative question.

Community
  • 1
  • 1
fuiiii
  • 1,359
  • 3
  • 17
  • 33