[web2py] Re: user profile fields for referenced table
if you had already logged in, you can retrieve current user logged in id using : auth.user_id after that just query it. e.g. rows = db(db.auth_user.id == auth.user_id).select().first() 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.
[web2py] Re: user profile fields for referenced table
So based on your answers I menaged to do my form The next question or problem I have is following. When user registers a new record is created in two tables (auth_user and organization). But when the user goes to profile page the form is empty and after filling it a new record is inserted in organization (only there) table. I would like to populate the form at the beginning and then update the table organization. how do I get the current user Id or users organization id or some other unique id to use it for update statement? any suggestions? thank you -- 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.
[web2py] Re: user profile fields for referenced table
i think you shouldn't define the auth_user table, just keep it default, and if you want to add the new field of auth_user table, please use extra_fields. e.g. # append fields : auth.signature db._common_fields.append(auth.signature) # custom auth user table add fields gender, address, zip_code, city, country, phone, branch, bank, account_no auth.settings.extra_fields['auth_user'] = [ Field('gender', label = T('Gender'), notnull = True, required = True, requires = IS_IN_SET({T('Male'), T('Female') } ) ), Field('address', 'text', label = T('Address'), notnull = True, represent = lambda address, field: A(address, _title=T(View Maps), _target=_blank, _href=http://maps.google.com/maps?f=qhl=engeocode=time=date=ttype=q=%s,+%s,+%s; % (field.address, field.city, field.country) ), required = True, requires = IS_NOT_EMPTY() ), Field('zip_code', label = T('Zip Code'), notnull = True, required = True, requires = IS_MATCH('^\d{5,5}$', error_message = 'not a Zip Code') ), Field('city', label = T('City'), notnull = True, required = True, requires = IS_NOT_EMPTY() ), Field('country', label = T('Country'), notnull = True, required = True, requires = IS_NOT_EMPTY() ), Field('phone', 'list:string', label = T('Phone'), notnull = True, required = True), Field('branch', 'reference branch', label = T('Branch'), notnull = True, required = True, requires = IS_IN_DB(db, db.branch.id, '%(address)s') ), Field('bank', 'reference bank', label = T('Bank'), notnull = True, represent = lambda bank, field: A(bank.bank, _title=T(eBanking), _target=_blank, _href=%s % bank.ebanking), required = True, requires = IS_IN_DB(db, db.bank.id, '%(bank)s') ), Field('account_no', label = T('Account No'), notnull = True, required = True, requires = IS_NOT_EMPTY() ), ] # create all tables needed by auth if not custom tables, add username field auth.define_tables(username = True, signature = True) custom_auth_table custom_auth_table = db[auth.settings.table_user_name] # label custom_auth_table.first_name.label = T('First Name') custom_auth_table.last_name.label = T('Last Name') custom_auth_table.email.label = T('Email') # represent custom_auth_table.email.represent = lambda email, field: \ A(email, _title=T(Send to %s) % email, _target=_blank, _href=mailto:%s; % email) # requires custom_auth_table.phone.requires = IS_NOT_IN_DB(db, custom_auth_table.phone) auth.settings.table_user = custom_auth_table 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.
[web2py] Re: user profile fields for referenced table
I left the default auth.create_table(migrate = setting.migrate) then added extra fields then deffined my table organization in user profile only first name, last name and email are shown where am I going wrong? On Tuesday, December 3, 2013 11:14:45 AM UTC+1, 黄祥 wrote: i think you shouldn't define the auth_user table, just keep it default, and if you want to add the new field of auth_user table, please use extra_fields. e.g. # append fields : auth.signature db._common_fields.append(auth.signature) # custom auth user table add fields gender, address, zip_code, city, country, phone, branch, bank, account_no auth.settings.extra_fields['auth_user'] = [ Field('gender', label = T('Gender'), notnull = True, required = True, requires = IS_IN_SET({T('Male'), T('Female') } ) ), Field('address', 'text', label = T('Address'), notnull = True, represent = lambda address, field: A(address, _title=T(View Maps), _target=_blank, _href= http://maps.google.com/maps?f=qhl=engeocode=time=date=ttype=q=%s,+%s,+%s; % (field.address, field.city, field.country) ), required = True, requires = IS_NOT_EMPTY() ), Field('zip_code', label = T('Zip Code'), notnull = True, required = True, requires = IS_MATCH('^\d{5,5}$', error_message = 'not a Zip Code') ), Field('city', label = T('City'), notnull = True, required = True, requires = IS_NOT_EMPTY() ), Field('country', label = T('Country'), notnull = True, required = True, requires = IS_NOT_EMPTY() ), Field('phone', 'list:string', label = T('Phone'), notnull = True, required = True), Field('branch', 'reference branch', label = T('Branch'), notnull = True, required = True, requires = IS_IN_DB(db, db.branch.id, '%(address)s') ), Field('bank', 'reference bank', label = T('Bank'), notnull = True, represent = lambda bank, field: A(bank.bank, _title=T(eBanking), _target=_blank, _href=%s % bank.ebanking), required = True, requires = IS_IN_DB(db, db.bank.id, '%(bank)s') ), Field('account_no', label = T('Account No'), notnull = True, required = True, requires = IS_NOT_EMPTY() ), ] # create all tables needed by auth if not custom tables, add username field auth.define_tables(username = True, signature = True) custom_auth_table custom_auth_table = db[auth.settings.table_user_name] # label custom_auth_table.first_name.label = T('First Name') custom_auth_table.last_name.label = T('Last Name') custom_auth_table.email.label = T('Email') # represent custom_auth_table.email.represent = lambda email, field: \ A(email, _title=T(Send to %s) % email, _target=_blank, _href=mailto:%s; % email) # requires custom_auth_table.phone.requires = IS_NOT_IN_DB(db, custom_auth_table.phone) auth.settings.table_user = custom_auth_table 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.
[web2py] Re: user profile fields for referenced table
I meanaged to add fileds, but insted of being the fileds of referenced table they were added to auth_user table all of them of type integer I want them to be read from table organization code in db.py auth.settings.extra_fields['auth_user']= [ Field('o_name','reference organization',label = T('Org name'),), Field('o_telnumber','reference organization'), Field('o_street','reference organization'), Field('o_city','reference organization'), Field('o_state','reference organization'), Field('o_country','reference organization'), Field('o_TaxNumber','reference organization'), Field('o_note','reference organization'), ] -- 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.
[web2py] Re: user profile fields for referenced table
i'm so sorry, didn't realize it, i think is it all about sequential, please define the organization table first and then auth.settings.extra_fields, auth.define_tables, custom_auth_table (for field constructor : label, required, requires, etc). e.g. # 1st db.define_table('organization', ) # 2nd auth.settings.extra_fields['auth_user'] = [ ... ] # 3rd auth.define_tables(username = True, signature = True) # 4th custom_auth_table = db[auth.settings.table_user_name] ... auth.settings.table_user = custom_auth_table 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.
[web2py] Re: user profile fields for referenced table
1 more thing, if you have reference field to another table it will refer to the table id of your target, so i think it's useless if you define a lot of auth user extra field to just 1 table, because it will return 1 value which is the table id, in this case will be organization id. 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.
[web2py] Re: user profile fields for referenced table
So how do i resolve that I have aut_user table that has a field organization (id) In table organization I have more fields (org name, adress, etc) Now I want to show this fields (almost all) of table organization to user in user profile view. ?? On Tuesday, December 3, 2013 1:34:06 PM UTC+1, 黄祥 wrote: 1 more thing, if you have reference field to another table it will refer to the table id of your target, so i think it's useless if you define a lot of auth user extra field to just 1 table, because it will return 1 value which is the table id, in this case will be organization id. 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.
[web2py] Re: user profile fields for referenced table
i think it will make the database table denormalization (make data redundancy) if you put almost all of your organization table value to your auth_user table. i think just refer the organization from auth_user table is more than enough, and if you want to know this user belong to which organization address, city, state, etc, then you can just query it. please examine the example code i gave first, you will see that my auth_user table is refer to table branch, which is have almost the same field like your (address, city, state), but in my case i just refer only one, if i want to know where is this user works in, i can query it in my example : db.auth_user.branch.address. e.g. db.define_table('company', Field('name'), Field('website'), Field('logo', 'upload'), format = '%(name)s') db.define_table('bank', Field('bank'), Field('ebanking'), format = '%(bank)s') db.define_table('branch', Field('address', 'text'), Field('zip_code'), Field('city'), Field('country'), Field('phone', 'list:string'), Field('fax', 'list:string'), Field('email', 'list:string'), Field('bank', 'list:reference bank'), Field('company', 'reference company'), format = '%(address)s') 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.
[web2py] Re: user profile fields for referenced table
where do you put he query db.auth_user.branch_adress? On Tuesday, December 3, 2013 1:54:57 PM UTC+1, 黄祥 wrote: i think it will make the database table denormalization (make data redundancy) if you put almost all of your organization table value to your auth_user table. i think just refer the organization from auth_user table is more than enough, and if you want to know this user belong to which organization address, city, state, etc, then you can just query it. please examine the example code i gave first, you will see that my auth_user table is refer to table branch, which is have almost the same field like your (address, city, state), but in my case i just refer only one, if i want to know where is this user works in, i can query it in my example : db.auth_user.branch.address. e.g. db.define_table('company', Field('name'), Field('website'), Field('logo', 'upload'), format = '%(name)s') db.define_table('bank', Field('bank'), Field('ebanking'), format = '%(bank)s') db.define_table('branch', Field('address', 'text'), Field('zip_code'), Field('city'), Field('country'), Field('phone', 'list:string'), Field('fax', 'list:string'), Field('email', 'list:string'), Field('bank', 'list:reference bank'), Field('company', 'reference company'), format = '%(address)s') 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.
[web2py] Re: user profile fields for referenced table
where do you put he query db.auth_user.branch_adress? I want the user to add company, not to choose from avaliable companies, but the data is inserted into organization table On Tuesday, December 3, 2013 1:54:57 PM UTC+1, 黄祥 wrote: i think it will make the database table denormalization (make data redundancy) if you put almost all of your organization table value to your auth_user table. i think just refer the organization from auth_user table is more than enough, and if you want to know this user belong to which organization address, city, state, etc, then you can just query it. please examine the example code i gave first, you will see that my auth_user table is refer to table branch, which is have almost the same field like your (address, city, state), but in my case i just refer only one, if i want to know where is this user works in, i can query it in my example : db.auth_user.branch.address. e.g. db.define_table('company', Field('name'), Field('website'), Field('logo', 'upload'), format = '%(name)s') db.define_table('bank', Field('bank'), Field('ebanking'), format = '%(bank)s') db.define_table('branch', Field('address', 'text'), Field('zip_code'), Field('city'), Field('country'), Field('phone', 'list:string'), Field('fax', 'list:string'), Field('email', 'list:string'), Field('bank', 'list:reference bank'), Field('company', 'reference company'), format = '%(address)s') 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.
[web2py] Re: user profile fields for referenced table
Have a look at http://web2py.com/books/default/chapter/29/07/forms-and-validators#One-form-for-multiple-tables . Anthony On Tuesday, December 3, 2013 7:37:34 AM UTC-5, Yebach wrote: So how do i resolve that I have aut_user table that has a field organization (id) In table organization I have more fields (org name, adress, etc) Now I want to show this fields (almost all) of table organization to user in user profile view. ?? On Tuesday, December 3, 2013 1:34:06 PM UTC+1, 黄祥 wrote: 1 more thing, if you have reference field to another table it will refer to the table id of your target, so i think it's useless if you define a lot of auth user extra field to just 1 table, because it will return 1 value which is the table id, in this case will be organization id. 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.
[web2py] Re: user profile fields for referenced table
where do you put he query db.auth_user.branch_adress? db.auth_user.branch.address not db.auth_user.branch_adress db.table.reference_table_field_from_table.field_of_reference_table it depend where i want to receive the query db.auth_user.branch.address result, e.g. if i want the result in models, i put it on models, if in controllers in put it on controllers, if in views i put it on views. I want the user to add company, not to choose from avaliable companies, but the data is inserted into organization table sorry, i'm just gave you an example, not to force you to follow mine, in example above is just to describe : 1. the order when i define the database table : e.g. the auth user table have refer to table branch, so that i must create / define branch table before i define auth user table 2. i'm show normalization in database to minimalize redundant data : e.g. i'm just define 1 field that refer to 1 table, even i want some information from that table, let say, i want to know where the auth_user is active, so like example above, i can query it using db.auth_user.branch.address. perhaps you can follow anthony reference to the book. you can imagine it that client table is auth_user table and address table is organization table. 1 more thing, if the client table field is added, for example add the new field gender, i think the address table only refer to client table once. 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.