Thanks for the replies. Now I try to add the ability to delete
records, but it doesn't seem to work:
db(db.input.virtualfields==session.virtualfields).delete()


>On Jan 3, 1:52 pm, Bruno Rocha <rochacbr...@gmail.com> wrote:
> [ Copy Paste Mystake ]
>
> Correct is:
>
> you have two options:
>
> 1. define the virtual fields in model
>
> =in a model file==
> db.define_table('input',
>        Field('value', 'integer'))
> class MyVirtualFields(object):
>        def input_number(self):
>                return self.input.value
>
> db.input.virtualfields.append(MyVirtualFields())
>
> 2. In controller use the setvirtualfields method of Rows
>
> ==in a controller file==
> records = db(db.input.id>0).select() # or any other query
> records.setvirtualfields(virtual=MyVirtualFields())
>
>
>
>
>
>
>
>
>
>
>
> > 2011/1/3 Rick <sababa.sab...@gmail.com>
>
> > Thanks for the advice. I changed my code, but I don't know if I'm on
> >> the right track. Anyhow it doesn't work.
>
> >> ==in a model file==
> >> db.define_table('input',
> >>        Field('value', 'integer'))
> >> class MyVirtualFields(object):
> >>        def input_number(self):
> >>                return self.input.value
>
> >> ==in a controller file==
> >> def create():
> >>        records = db().select(db.day.ALL, orderby=db.day.thedate)
> >>         form = SQLFORM(db.input, fields=['value'])
> >>         db.day.virtualfields.append(MyVirtualFields())
> >>        return dict(form = form)
> >> def deleterec():
> >>        session.virtualfields.remove(MyVirtualFields())
> >>        db.input.input_number.remove(MyVirtualFields())
> >>        redirect(URL('create'))
>
> >> ==in create.html==
> >> {{for record in records:}}
> >>        {{session.virtualfields=record.virtualfields}}
> >>        {{=record.value}} : [ {{=A(("Delete this record"),
> >> _href=URL('deleterec'))}}
>
> >> >On Jan 2, 10:36 pm, Kenneth Lundström <kenneth.t.lundst...@gmail.com>
> >> wrote:
> >> > If you only want to display a number I guess virtual fields is what you
> >> > need. Look at
>
> >> >http://www.web2py.com/book/default/chapter/06?search=virtual#Virtual-.
> >> ..
>
> >> > Kenneth
>
> >> > > Hi,
> >> > > In addition to the records that are submitted with a SQLFORM, I want
> >> > > to give each record a specific "identification" number, so that the
> >> > > first record has number=1 and so on:
>
> >> > > ==from model/db.py==
> >> > > db.define_table('input',
> >> > >    Field('number', 'integer'),
> >> > >    Field('value', 'integer'))
>
> >> > > ...My problem is that I don't know how to automatically add the number
> >> > > to this form:
> >> > > form = SQLFORM(db.input, fields=['value'])
>
> >> > > Thanks in advance for help.
>
> > --
>
> > Bruno Rocha
> >http://about.me/rochacbruno/bio
>
> --
>
> Bruno Rochahttp://about.me/rochacbruno/bio

Reply via email to