This is a problem:

db.define_table(
    'sale',
    Field('id', db.auth_user, default=auth.user_id),

How about this instead:
db.define_table(
    'sale',
    Field('user_id', db.auth_user, requires=IS_IN_DB( # See "Forms and 
Validators in the Fine Manual

Also do this:
db.define_table(
    'product',
    Field('sale_id', db.sale, requires=IS_IN_DB( # See "Forms and 
Validators in the Fine Manual

Also I would not use the double data type for currency. Use instead Python 
decimal which works as you expect decimal numbers to work. Or you could 
store the, for example, US currency as pennies and put in the decimal 
marker when you display the value and strip it out when you work with it on 
the back end.

Whatever comes in on request.post_vars and ends up in form.vars is a 
string.  Your database adapter takes care of conversions.




On Wednesday, October 16, 2013 1:36:53 PM UTC-4, raferbop wrote:
>
> Thanks Stifan, 
>
> But that doesn't work either, because the product_id now displays in the 
> sale form. I need to generate the sale_id first, and then have sow in the 
> product table/form. Right now, it just shows up blank. 
>
> On Wednesday, October 16, 2013 11:08:58 AM UTC-5, 黄祥 wrote:
>>
>> yeah, my pov is because your product never save the sale id. imho, i 
>> think your code should be :
>> db.define_table(
>>     'sale',
>>     Field('product_id', 'reference product'),
>>     Field('user_id', db.auth_user, default=auth.user_id),
>>     Field('start_date', 'date', requires=IS_DATE()),
>>     Field('end_date', 'date', requires=IS_DATE()),
>>     Field('start_time', 'time', requires = IS_TIME()),
>>     Field('end_time', 'time', requires = IS_TIME()))
>>
>> db.define_table(
>>     'product',
>>     Field('name', requires = IS_NOT_EMPTY()),
>>     Field('price', 'double', default=0.00),
>>     Field('description','text'),
>>     Field('image', 'upload', default=''),
>>     format = '%(name)s %(price)s')
>>
>> because 1 sale has many product and each product belongs to sale, isn't 
>> it?
>> 1 more thing please don't use id as your field name, because by default 
>> web2py use it as a primary key.
>> taken from book :
>>
>>    - Each table must have a unique auto-increment integer field called 
>>    "id"
>>    - Records must be referenced exclusively using the "id" field.
>>
>> ref:
>>
>> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Legacy-databases-and-keyed-tables
>>
>> best regards,
>> stifan
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to