I try what Jay suggest, that works, but since eval is risky and not
required, here what I come up with :
inputs_list = []
for a in my_dict:
inputs_list.append(Field(my_dict[a]['field_name']+'_f1',
type='boolean', widget=SQLFORM.widgets.checkboxes.widget,
req
Good one Serbitar. Much better than my solution. When I saw your "I
dont get it" post, I was reminded of why JavaScript functions return
functions instead of values.
So they can capture the scope too.
Now you have to call this every time you have to access this table, is
that right?
On Apr 10, 5
OK got it. Lambda functions dont save their scope.
Here is the right code:
list = ["a","b","c","d"]
fields = []
for entry in list:
fields += [Field(entry, type="string")]
db.define_table('test', *fields)
class MyVirtualFields(object):
pass
def get_func(value):
def func(self):
Strange. My example from earlier does not work. It returns always the
last call from func.
list = ["a","b","c","d"]
fields = []
for entry in list:
fields += [Field(entry, type="string")]
db.define_table('test', *fields)
class MyVirtualFields(object):
pass
for entry in list:
def func
Next question is:
How do I attach a label to a virtual field?
Right. My problem was not the function itself, but how to generally
create a dynamic virtual field with dynamic fields as computation
variables (in this case from a given list).
On Apr 10, 12:02 am, Anthony wrote:
> To create virtual fields, you first have to define a class, such as:
>
> class My
Have the solution:
Dynamic Fields:
list = ["a","b","c","d"]
fields = []
for entry in list:
fields += [Field(entry, type="string")]
db.define_table('test', *fields)
Dynamic virtual Fields:
class MyVirtualFields(object):
pass
for entry in list:
def func(self):
return getattr
On Saturday, April 9, 2011 7:34:25 AM UTC-4, Serbitar wrote:
>
> Sorry, misstyped and sent the message early. So once again:
>
> I can create database fields from a list like this:
>
> list = ["a","b","c","d"]
> fields = []
> for entry in list:
> fields += [Field(entry, type="string")]
>
Hm, that might be a last resort. I am trying to do something more in
line with settatr, but unfortunately, even the fields to compute the
virtual fields are variables and not strings in the function, which is
also named after the virtual table instead of being a string argument.
Seems quite tricky.
I use this method for generating totally dynamic forms.
1. Create an array, say out
2. Append "Field(, , )" to this array for all
fields I need - note this is a string, no function calls
3. Wrap the above in an SQLFORM statement.
formstring = 'SQLFORM.factory(' +','.join(out)+')'
4. Then eval th
Sorry, misstyped and sent the message early. So once again:
I can create database fields from a list like this:
list = ["a","b","c","d"]
fields = []
for entry in list:
fields += [Field(entry, type="string")]
db.define_table('test', *fields)
Now I want to have a virtual field for each field i
11 matches
Mail list logo