Multiple entities through forms

6 views
Skip to first unread message

César Fernández

unread,
Mar 15, 2011, 11:44:31 AM3/15/11
to TurboGears
Hi everybody, i'm trying to create new entities in my app from a list
of entities related to one of them. I mean, i have one enterprise
selected and i'm listing all of its stuff in a list. This is part of
my model:

class Enterprise(DeclarativeBase):
__tablename__ = 'enterprise'
id = Column(Integer, primary_key=True)
name = Column(Unicode, nullable=False)
[...]
contacts = relationship('Contact', backref='Enterprise')
connection = relationship('Conection', backref='Enterprise')
[...]

One enterprise have one or more contacts and (internet) connections.
So in an html list i want a link to call a method where i can create
one contact related to that enterprise i'm seeing. My idea would be to
create a link to a method where i can guess the id of the enterprise
and create a contact related to that id without selecting the
enpterprise from a singleselectfield.

Until now i create a link this way, in the template:

<th><a href="${tg.url('/enterprise/new/' + str(enterprise.id))}">Edit</
a></th>

So, in the controller i can see the id (kw['id']) of the enterprise
and edit that, but now i want to tell the method that i have that
enterprise and i want to create a contact related to that enterprise.
Any idea?

I don't know how to search for this info in the documentation. I'm
using toscawidget and turbogears 2.1. If anybody want to see more code
i can post it.

Thanks in advance.

Michael Pedersen

unread,
Mar 23, 2011, 9:13:57 PM3/23/11
to turbo...@googlegroups.com
Is there any reason you couldn't use something like this in your Enterprise form template?

<a href="${tg.url('/contacts/new/" + str(enterprise.id))}">New Contact</a>

Then, in your new contact form, you snag that id, and display whatever you wish to display.

2011/3/15 César Fernández <darkschn...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to turbo...@googlegroups.com.
To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.




--
Michael J. Pedersen
My IM IDs: Jabber/pede...@icelus.tzo.com, ICQ/103345809, AIM/pedermj022171
          Yahoo/pedermj2002, MSN/pederm...@hotmail.com

César Fernández

unread,
Mar 24, 2011, 4:06:10 AM3/24/11
to turbo...@googlegroups.com
Yeah, 'm sorry, i've found the way and i didn't post the solution, i
forgot to report it.

In fact i was trying to do something weird, at the end i've used an
explicit '?empresa=' to pass the id through the link. And i've added a
new method to handle that situation.

Thanks anyway. If somebody wants the entire code ask me to post it.

2011/3/24 Michael Pedersen <m.ped...@icelus.org>:

--
There's no religion but sex and music
  -- Sting

Reply all
Reply to author
Forward
0 new messages