Unfortunately the code bellow seems to be errors-prone:

==in a model file==
class MyVirtualFields(object):
        def input_number(self):
                return some_variable
db.input.virtualfields.append(MyVirtualFields())


>On Jan 3, 8:03 pm, Rick <sababa.sab...@gmail.com> wrote:
> Perhaps this would be a good idea to keep track of the records:
>
> ==in a model file==
> n = 0
> class MyVirtualFields():
>         def day_number(self):
>                 n=n+1
>                 return n
>
> but I'm not sure about how to write this idea properly in python.
> Perhaps there should be some kind of loop in the controller file?
>
> On Jan 3, 7:39 pm, Rick <sababa.sab...@gmail.com> wrote:
>
>
>
>
>
>
>
> > 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