[web2py] autoincremente field with a specific first value

2012-08-11 Thread tigmmi
Is there a way to add an autoincremente field with a specific first value. 
Compute won't work with id + number.

-- 





[web2py] Re: Having trouble with computed fields referencing id field.

2012-08-11 Thread tigmmi
I have the same problème and in that poste : 
https://groups.google.com/forum/?fromgroups#!topic/web2py/RmdCe7xp5gM[1-25] 
it say that it's possible to do so but in my test application it's not.
As you say on insertion the id is not avaaillable yet and that is the 
raison I think.

If somme body have a solution, please give as a sample of code.

On Monday, August 6, 2012 12:14:52 AM UTC, Rob_McC wrote:
>
>
> . I created a simple app, with only this in it,
> . I can get computed field to work , but never referencing the id field.
>
> I think the trouble is that 'id' is never updated, so it is not available 
> for compute= .
> I don't think I can do this when the record is first created, since an 
> 'id' has not been assigned.
>
> I want to eventually add another field that depends on 'id' that is why 
> I'm doing this.
>
> I could use a virtual field I think...
>
> Thanks 
> Rob
>
>
>
>
>
> ## after auth = Auth(db)
> auth.settings.extra_fields['auth_user']= [
>   Field('address'),
>   Field('city'),
>   Field('zip'),
>   Field('phone'),
>   Field('ref_number', compute=lambda r: r['city'])]
>
>
> # this WORKS
> #  Field('ref_number', compute=lambda r: r['city'])]
>
>
> # this DOES NOT WORK
> #   Field('ref_number', compute=lambda r: r['id'])]
> #   Field('ref_number', 'integer', compute=lambda r: r['id'])]  
>
>
> # before auth.define_tables(username=True)
>
>
> ## create all tables needed by auth if not custom tables
> auth.define_tables()
>
>

-- 





[web2py] Re: autoincremente field with a specific first value

2012-08-14 Thread tigmmi
I would like to have it on insert. Like for example a mouvement number that 
start with 100 not 1 as is the case for id.
I have foud another alternative in fiorm.accepts():
def index():
"""
example action using the internationalization operator T and flash
rendered by views/default/index.html or views/generic.html
"""
form = SQLFORM(db.bs)
if form.accepts(request.vars,session):
   db(db.bs.id==form.vars.id).update(Numero=db.bs.id + 100);
return dict(form=form)

But I still cannot declare Number as not null and unique.

On Monday, August 13, 2012 4:06:57 AM UTC, Massimo Di Pierro wrote:
>
> Do you mean something like this?
>
> db(query).update(field = db.table.field+value)
>
> On Friday, 10 August 2012 10:46:54 UTC-5, tigmmi wrote:
>>
>> Is there a way to add an autoincremente field with a specific first 
>> value. Compute won't work with id + number.
>
>

-- 





[web2py] Re: autoincremente field with a specific first value

2012-08-14 Thread tigmmi
I would like to have it on DAL mysql specific.
I found the _befor_insert and other events very intresent and can hel in 
many part of my code. Thansk to Massimo.

On Monday, August 13, 2012 6:33:59 PM UTC, Cliff Kachinske wrote:
>
> In MySQL there is 
>
> ALTER TABLE mytable AUTO_INCREMENT = 500
>
> Is that what you want to do?
>
> On Friday, August 10, 2012 11:46:54 AM UTC-4, tigmmi wrote:
>>
>> Is there a way to add an autoincremente field with a specific first 
>> value. Compute won't work with id + number.
>
>

--