Re: How to exclude some fields from a form for a database record?

99 views
Skip to first unread message

Alan Etkin

unread,
Mar 22, 2013, 12:45:29 PM3/22/13
to web...@googlegroups.com
>  Do I just need to write a custom form and a custom handler for the post, or is there an easy way to do this?

You could set the the readable and writable attributes to False only if the scaffolding registration action is called:

if request.function == "user" and "register" in request.args:
    db.auth_user.custom_field.readable = db.auth_user.custom_field.writable = False

David Ripplinger

unread,
Mar 22, 2013, 1:59:41 PM3/22/13
to web...@googlegroups.com
I found a cleaner solution after some digging. In db.py, after creating the auth object, include the line:

auth.settings.register_fields = ['id', 'first_name', 'last_name', 'email', 'password']

or if when you created the auth object you passed in username=True, include the line:

auth.settings.register_fields = ['id', 'first_name', 'last_name', 'email', 'username', 'password']

This list is by default None, which actually means grab everything from the auth_user database fields. By setting it to a fixed list, you can control which of the auth_user fields are actually used in the registration form.

On Thursday, March 21, 2013 4:34:47 PM UTC-4, David Ripplinger wrote:
I recently found out how to add an additional field to the auth_user table, but then I found that the registration page for a new user has a spot in the form to input a value for the extra field. In many cases, this is desired, but I want this particular field to not appear in the registration form. It is set to default to None, so the database doesn't complain about not getting a value for it, but I need to remove the field's input line from the form. Do I just need to write a custom form and a custom handler for the post, or is there an easy way to do this?

Thanks.

Alan Etkin

unread,
Mar 22, 2013, 5:29:41 PM3/22/13
to web...@googlegroups.com
A good one. And for you initial requirement which was taking a particular field out of the form (not choosing the whole set of fields that the registration form should show), this is more compact, specially if you are populating the scaffolding auth_user table with custom fields:

auth.settings.register_fields = db.auth_user.fields()
auth.settings.register_fields.remove("<field to remove>")

Reply all
Reply to author
Forward
0 new messages